I'm currently trying to get validation going in a custom section I created. The properties on the view that I used are part custom; just textboxes and so on and part umbraco property editors where I fetch the config via API call.
Now the problem that I'm facing is with date/time-picker. The picked value is shown correctly but the form still stays on error state. So my tab where the pickers are on is red to indicate errors on the page. When I check if the form is valid by using $scope.form.$valid it says that it has pickerErrors.
I tried using the formHelper to do validation and it returns no errors. So the form seems to be valid for the form helper.
I'm rendering the property editors like this:
<umb-property property="picker" ng-repeat="picker in startDateTimePickers">
<umb-editor model="picker"></umb-editor>
</umb-property>
interesting fact is my create and edit method uses the same controller and views. During creation the validation works as expected but not when editing.
One speciality might be that I have multiple tabs in my edit view with each tab has its own view and controller handling loading of assets or handling the watches like mentioned above.
Yes it works correctly when creating an entity.
But the view/controller is the same when creating or editing.
Basic setup of my pages is on view for the general edit view. Depending on the entity type it includes different additional views in its main body.
The picker itself also creates a scope and has also a controller. Default umbraco behaviour.
My problem is that I don't understand what the difference is between create and edit. Besides the values that are passed to the date picker when it is created. When on create its moment(new Date()).format('picker_format').
When on edit its moment(entty.date).format('picker_format').
when checking the pickerErrors that I output to console it shows that modelValue of the picker is 'Invalid Date'. Which could be the reason - but it shows the date correctly and also changing the date doesn't remove the error.
It looks like the pickerErrors is set explicitly using $setValidity, so it might be useful if you can debug into that, and see why the date is invalid. There might be some regex or similar going on?
Is your entty.date a Date object? Or could that be a string?
Maybe you could even copy paste the source into your own directive and debug the issue that way?
That hint with the date object and string is indeed an interesting idea.
But I think moment should return strings in both use-cases; with date object or the entity.date. Which is a DateTime parsed to json.
I will have a look at the source and try a bit with string and date objects and see what I can find out.
Ok I think I found it and it was my own stupidity.
I had more then one date/time picker on my view. And in fact the error was thrown by some that were not shown as they were not needed for that specific entity.
So after removing them from the DOM it worked.
Now on to test everything. Like create and edit of all my entity shapes.
Validation in custom section
Hi,
I'm currently trying to get validation going in a custom section I created. The properties on the view that I used are part custom; just textboxes and so on and part umbraco property editors where I fetch the config via API call.
Now the problem that I'm facing is with date/time-picker. The picked value is shown correctly but the form still stays on error state. So my tab where the pickers are on is red to indicate errors on the page. When I check if the form is valid by using $scope.form.$valid it says that it has pickerErrors.
I tried using the formHelper to do validation and it returns no errors. So the form seems to be valid for the form helper.
I'm rendering the property editors like this:
I create the editor like this:
My form is rendered like this in the view:
And I check if the form is valid like this:
I move the selected date value with a $watch to my model:
I tried to use the formHelper to check validy with:
interesting fact is my create and edit method uses the same controller and views. During creation the validation works as expected but not when editing.
One speciality might be that I have multiple tabs in my edit view with each tab has its own view and controller handling loading of assets or handling the watches like mentioned above.
Any help?
So the datepicker works and validates correctly in the create view?
And on the edit page, the datepicker is nested within an additional controller?
Could it be somehow related to nested $scopes?
Yes it works correctly when creating an entity. But the view/controller is the same when creating or editing.
Basic setup of my pages is on view for the general edit view. Depending on the entity type it includes different additional views in its main body.
The picker itself also creates a scope and has also a controller. Default umbraco behaviour.
My problem is that I don't understand what the difference is between create and edit. Besides the values that are passed to the date picker when it is created. When on create its
moment(new Date()).format('picker_format')
. When on edit itsmoment(entty.date).format('picker_format')
.when checking the pickerErrors that I output to console it shows that modelValue of the picker is 'Invalid Date'. Which could be the reason - but it shows the date correctly and also changing the date doesn't remove the error.
It might help to take a look at the source:
https://github.com/umbraco/Umbraco-CMS/tree/dev-v7/src/Umbraco.Web.UI.Client/src/views/propertyeditors/datepicker
It looks like the pickerErrors is set explicitly using $setValidity, so it might be useful if you can debug into that, and see why the date is invalid. There might be some regex or similar going on?
Is your entty.date a Date object? Or could that be a string?
Maybe you could even copy paste the source into your own directive and debug the issue that way?
That hint with the date object and string is indeed an interesting idea. But I think moment should return strings in both use-cases; with date object or the entity.date. Which is a DateTime parsed to json.
I will have a look at the source and try a bit with string and date objects and see what I can find out.
Thanks for the hint and the help!
Ok I think I found it and it was my own stupidity.
I had more then one date/time picker on my view. And in fact the error was thrown by some that were not shown as they were not needed for that specific entity.
So after removing them from the DOM it worked. Now on to test everything. Like create and edit of all my entity shapes.
Thanks anyway for the hints!
is working on a reply...