Is it possible to make a datatype mandatory depending on a different datatype? For example if I have a checkbox datatype if it's checked I'd like other datatypes to become mandatory on the page. Is this possible? Could this be done creating some custom datatypes? Hope someone has experience with this.
If this is not possible does someone know how I can make a custom datatype mandatory? For example in the axendo form designer you have a Axendo Form Mailer datatype which only becomes mandatory when the checkbox active is checked.
No solution out of the box, but event handlers may be an option by cancelling out a save until all mandatory fields have been filled in (not the most elegant solution, but would work)
I do like the idea of having options to make custom datatypes mandatory, should be possible to extend current datatype core to include a Valid property, and have the property implemented by custom datatypes.
Thanks to Ron Brouwer who build the Axendo Form Designer this problem was solved. He sended me a little sample code how the Axendo Form Designer uses Validation. This is done by creating a custom validator which does the checking. Here is a sample I'm currently using:
/// <summary>
/// Validate a WebControl with a custom validator. If the checkbox is checked the WebControl is mandatory.
/// </summary>
/// <param name="source"></param>
/// <param name="args"></param>
protected void ValidateWebControl(object source, ServerValidateEventArgs args)
{
args.IsValid = true;
if (!CheckEmail.Checked)
{
//Skip validation if the checkbox is not checked.
return;
}
if (args.Value == string.Empty)
{
//Set validation to false if no value is entered into the WebControl.
args.IsValid = false;
//Get the CustomValidator.
CustomValidator validator = (CustomValidator)source;
if (!string.IsNullOrEmpty(validator.Text))
{
//Display the errormessage in the same style Umbraco does.
validator.ErrorMessage = validator.Text + " is een verplicht veld.";
validator.Text = null;
}
}
}
You don't need to use a validation group because Umbraco checkes all validators. With this code you can make webcontrols mandatory if the checkbox is checked.
Linked mandatory datatypes
Hello,
Is it possible to make a datatype mandatory depending on a different datatype? For example if I have a checkbox datatype if it's checked I'd like other datatypes to become mandatory on the page. Is this possible? Could this be done creating some custom datatypes? Hope someone has experience with this.
If this is not possible does someone know how I can make a custom datatype mandatory? For example in the axendo form designer you have a Axendo Form Mailer datatype which only becomes mandatory when the checkbox active is checked.
Hope someone can help me.
No solution out of the box, but event handlers may be an option by cancelling out a save until all mandatory fields have been filled in (not the most elegant solution, but would work)
I do like the idea of having options to make custom datatypes mandatory, should be possible to extend current datatype core to include a Valid property, and have the property implemented by custom datatypes.
Cheers,
/Dirk
Thanks to Ron Brouwer who build the Axendo Form Designer this problem was solved. He sended me a little sample code how the Axendo Form Designer uses Validation. This is done by creating a custom validator which does the checking. Here is a sample I'm currently using:
Front-end:
Back-end:
You don't need to use a validation group because Umbraco checkes all validators. With this code you can make webcontrols mandatory if the checkbox is checked.
is working on a reply...