How to put an validation for selected value of dropdown datatype.
Hi All..
I am using custom dropdown datatype for countries as a member property. I want to make it compulsory. And also I want to insert one option of "Choose" in dropdown. And while saving I want to choose if the country was selected. I have used ASP.Net user control to created custom datatype for dropdown. Can anyone guide how I should validate the selected value is Country?
Thanks @dawoe. It looks to be an good option. But in my case, I have currency dropdown also. And might get some more dropdowns in future. So is there any other way to put validation?
Are you using any compiled code? You would probably want a model with your drop down as a property and then have a custom validation attribute on the property. Charlie :)
Hi Charles.. I am using ASP.Net user control for fetching ucommerce currency and countries. Then I use this user controls for creating custom datatypes for currency and countries. I think, by using ASP.Net user control I cant use the Model and Valiation attribute approach. Or would you please more elaborate on it?
Dawoe.. I have an custom datatype for countries and currencies. Ucommerce countries and currencies are fetched using user controls. With the countries and currencies, we want to insert one more option Saying "Choose" which will be selected at first. We are using this datatype for member types. And also we want to enforce validation that country/currency is selected. That mean somehow I want to check if I have selected choose option, And I can show validation message. So far I dont see docType envolved in this scenario :(
I have set the property as mandatory . And also value for "Choose" is kept empty (havenot added value, or did you mean blank - "") . But it is not working. Following is the syntax I add the "Choose" option to dropdown :
ddlCountries.Items.Insert(0, new ListItem() { Text="Choose"}); // value not added
How to put an validation for selected value of dropdown datatype.
Hi All..
I am using custom dropdown datatype for countries as a member property. I want to make it compulsory. And also I want to insert one option of "Choose" in dropdown. And while saving I want to choose if the country was selected. I have used ASP.Net user control to created custom datatype for dropdown. Can anyone guide how I should validate the selected value is Country?
Maybe you can use this datatype and don't need to create it your self : http://our.umbraco.org/projects/backoffice-extensions/country-picker-property-editor
Thanks @dawoe. It looks to be an good option. But in my case, I have currency dropdown also. And might get some more dropdowns in future. So is there any other way to put validation?
Are you using any compiled code? You would probably want a model with your drop down as a property and then have a custom validation attribute on the property. Charlie :)
Hi Charles..
I am using ASP.Net user control for fetching ucommerce currency and countries. Then I use this user controls for creating custom datatypes for currency and countries. I think, by using ASP.Net user control I cant use the Model and Valiation attribute approach. Or would you please more elaborate on it?
Charles.. I am still not able to resolve the issue. Any one has any idea how I can move ahead?
You can mark the property to be required on you doctype.
Dawoe.. I have an custom datatype for countries and currencies. Ucommerce countries and currencies are fetched using user controls. With the countries and currencies, we want to insert one more option Saying "Choose" which will be selected at first. We are using this datatype for member types. And also we want to enforce validation that country/currency is selected. That mean somehow I want to check if I have selected choose option, And I can show validation message. So far I dont see docType envolved in this scenario :(
I meant membertype. So if you dropdown option "Choose" has a empty value. You can mark the property to be mandatory on your membertype.
I have set the property as mandatory . And also value for "Choose" is kept empty (havenot added value, or did you mean blank - "") . But it is not working. Following is the syntax I add the "Choose" option to dropdown :
Should I use regex ?
You should also set the value for your choose item. If not set the Text property will be used for the value.
Yup.. Setting Value = "" solved the issue. Thank you :)
is working on a reply...