(Sorry if this is the wrong category; I can't seem to figure out how to put it in Extending Umbraco and Using the API)
I'm working on a custom Conditional Logic property editor that essentially holds conditional logic for other properties of a specific element or content type. Without going into too much detail on the context, here's what's going on:
The Conditional Logic configuration includes:
a specific content/element type (which should be the content/element type it is used on)
one or more conditions based on the other properties and groups of the selected content/element type.
For example, show the Circumference property and make it mandatory if the Shape property value is equal to "Circle":
Which means that Circumference is hidden and not mandatory when the Shape selected is something other than Circle:
I've only used this on element types (in a block list) so far.
The problem I'm running into is with conditionally mandatory fields. I've been able to get a jQuery object of the correct umb-property element, and I'm able to use this to modify the mandatory property:
This successfully toggles the visual appearance, but for some reason setting mandatory to true seems to break the client-side validation of the entire block, even for other properties that have not been directly modified. (The Conditional Logic property editor JS does also call $setInvalid on the conditionally required property when the form is submitting, but I've confirmed that setting the mandatory property to true is definitely what's causing the issue.)
For example, if there's a textbox property with a value that exceeds its character limit, and it's in the same block as a property that has been dynamically changed to mandatory, then the Save and Publish will go through without showing errors for either property.
This appears to be a result of the invalid and valid states not being propagated up to the form correctly:
The textbox will correctly show the message when its character limit has been exceeded
I've confirmed that the $setInvalid for the textbox and the conditionally required field are executing
But for some reason when the formHelper's submitForm function is running, the $valid and $invalid properties of the currentForm are both undefined (despite the fact that its $error property appears to contain the correct errors).
Can anyone think of why this might be breaking the client-side validation of the whole block, or whether there's a safer way to modify whether a property is mandatory on just the client side? (If I just change that property to mandatory in the settings, then it's still mandatory and will be caught by server-side validation even when it should be hidden.)
Backoffice: Dynamically change validation.mandatory
(Sorry if this is the wrong category; I can't seem to figure out how to put it in Extending Umbraco and Using the API)
I'm working on a custom Conditional Logic property editor that essentially holds conditional logic for other properties of a specific element or content type. Without going into too much detail on the context, here's what's going on:
The Conditional Logic configuration includes:
For example, show the Circumference property and make it mandatory if the Shape property value is equal to "Circle":
Which means that Circumference is hidden and not mandatory when the Shape selected is something other than Circle:
I've only used this on element types (in a block list) so far.
The problem I'm running into is with conditionally mandatory fields. I've been able to get a jQuery object of the correct umb-property element, and I'm able to use this to modify the mandatory property:
This successfully toggles the visual appearance, but for some reason setting
mandatory
to true seems to break the client-side validation of the entire block, even for other properties that have not been directly modified. (The Conditional Logic property editor JS does also call$setInvalid
on the conditionally required property when the form is submitting, but I've confirmed that setting the mandatory property to true is definitely what's causing the issue.)For example, if there's a textbox property with a value that exceeds its character limit, and it's in the same block as a property that has been dynamically changed to mandatory, then the Save and Publish will go through without showing errors for either property.
This appears to be a result of the invalid and valid states not being propagated up to the form correctly:
$setInvalid
for the textbox and the conditionally required field are executingformHelper
'ssubmitForm
function is running, the$valid
and$invalid
properties of thecurrentForm
are both undefined (despite the fact that its$error
property appears to contain the correct errors).Can anyone think of why this might be breaking the client-side validation of the whole block, or whether there's a safer way to modify whether a property is mandatory on just the client side? (If I just change that property to mandatory in the settings, then it's still mandatory and will be caught by server-side validation even when it should be hidden.)
is working on a reply...