I have an application which has two kinds of donors: individuals and organizations. Each donor type has different required fields. When organization is selected as the donor type, I want to prompt the user to select an organization type before adding/saving.
Organization type is required for organizations.
I'm looking for a simple example of how to do this.
Thanks in advance.
5 Answers, 1 is accepted
Attached to this reply you will find an example demonstrating the desired functionality. The activation of the DropDownList validation is realized with this setRequiredAttr function:
function
setRequiredAttr(evt) {
if
(evt.sender.element[0].value ===
"1"
) {
console.log(
"value is 1"
);
$(
"#OrganizationType"
).removeAttr(
"data-val-required"
);
}
else
{
console.log(
"value is 2"
);
$(
"#OrganizationType"
).attr(
"data-val-required"
,
"This field is required, please choose an option."
);
}
}
The above code is being executed on change event in the DropDownList from which we select the donor type – individual or organization. Depending on this selection we add or remove the data-val-required attribute from the input of the second DropDownList (the one for selecting the organization type).
Please check the proposed implementation and let me know if you have any questions regarding it.
Looking forward to your reply.
Petar
Progress Telerik
Take your time to try the proposed implementation and let me know if you need further assistance.
Regards,
Petar
Progress Telerik
Your solution works well except for one minor issue.
If I create an Individual type record after having created an Organization type record with the required organization type, it's possible to save that individual record with the organization type of the previously saved record. Ideally, I'd like to reset the organization drop-down after the creation of a record (since it would be fairly easy for a user to save an organization with the previous type (which could be incorrect).
I'm working on this now.
Thanks again for your help.
On form submit you can select the default value of the DropDownList using the select method like it is demonstrated in the following snippet:
$(
"#OrganizationType"
).kendoDropDownList().data(
"kendoDropDownList"
).select(1);
Regards,
Petar
Progress Telerik