How to add Custom Validation for select box?

At Widget : 

## define unique form input names :

#set ($persona = $core_v2_widget.UniqueId('persona'))

<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function(j){

j.microsoft.dynamics.widgets.userCreate.register({
wrapper: '#$core_v2_encoding.JavascriptEncode(${core_v2_widget.WrapperElementId})',
inputs: {
persona: "#$core_v2_encoding.JavascriptEncode($persona)",
},

resources: {
personaInvaild: "$core_v2_encoding.JavascriptEncode($core_v2_language.GetResource('CreateNewAccount_InvalidPersona'))"
},

At .vm File : 

<div class="form-group field-item required persona">
<label class="meta-large" for="$core_v2_encoding.HtmlAttributeEncode($persona)">$core_v2_language.GetResource('CreateNewAccount_Persona')</label><span class="field-item-validation" title="$core_v2_language.GetResource('RequiredTitleText')">*</span><br/>
<select name="persona" id="$core_v2_encoding.HtmlAttributeEncode($persona)">
<option value="">Select Profession</option>
<option value="IT Professional">IT Professional</option>
<option value="CFO">CFO</option>
</select>
</div>

At ui.js:

context.inputs.persona.live('change', function () {
context.elements.createAccountLink.evolutionValidation('validate');
});

if(context.inputs.persona.value != "") {
//alert("alert");
context.elements.createAccountLink.evolutionValidation('addField',
context.inputs.persona,
{
required: true,
persona: true,
messages: {
persona: context.resources.personaInvaild,
required: context.resources.fieldRequired
}
},
context.inputs.persona.closest('.field-item').find('.field-item-validation'), null);
}

There is some issue when we are selecting any option from select box, the code in ui.js is not working. Kindly Suggest how we can solve this issue.

Thanks 

Parents Reply Children
No Data