Question

I'm trying to set novalidate property to the easyUI validatebox in Jquery's (document).ready() method with the code:

$('#fieldId').attr('novalidate',true);

But it is not executing please help me to find the way to set the property.

Note

I'm using latest easyUI Library for form validation. When i set the property in data-options="novalidate:true", form validating code $(this).form('validate');won't validates the respective form field.

Thank you.

Part of HTML code:

Listed few fields get values from the database and fields will be disabled for the user.

<input type="text" id="field1" class="easyui-validatebox" required="true" data-options="validType:'justText'"> 
<input type="text" id="field2" class="easyui-validatebox" data-options="validType:'justText'"> 
<input type="text" id="field3" class="easyui-validatebox" required="true" data-options="validType:'justText'">
<input type="text" id="field4" class="easyui-validatebox" required="true" data-options="validType:'justText'">
<input type="text" id="field5" class="easyui-validatebox" required="true" data-options="validType:'justText'">
<input type="text" id="field6" class="easyui-numberbox" data-options="precision:1,validType:'correctValue'" required="true">
<input type="text" id="field7" class="easyui-numberbox" required="true" data-options="validType:'minLength[10]',prefix:0">

Similarly I have fields where user has to enter values.

<input type="date" id="field11" class="easyui-datebox" data-options="formatter:myformatter,parser:myparser,validType:'isAfterToday',required:true">

<input type="date" id="field13" class="easyui-datebox" data-options="formatter:myformatter,parser:myparser,validType:'isApproved[field11]',required:true">

On form load I will disable the fields as shown:

window.onload = function() {
    document.getElementById('field1').disabled=true;
    document.getElementById('field1').value='Ravi';
    document.getElementById('field2').disabled=true;
    document.getElementById('field2').value='cn';
    document.getElementById('field3').disabled=true;
    document.getElementById('field3').value='KM';
    document.getElementById('field4').disabled=true;
    document.getElementById('field4').value='Software Engineer';
}

Then user has to enter the values for enabled fields when they submit the form it should validate the form.

What happening with my form is if I enable the fields, form validates successfully else form validation returns false.

If I add property novalidate:true to the disabled fields form validates succeeds even the fields are disabled. Disabling and enabling depends on user access so that i can set this property as static It must be dynamic.

<input type="text" id="field2" class="easyui-validatebox" data-options="validType:'justText',novalidate:true">

Form validation code

$('#ff').form({
    onSubmit:function() {
      var isValid = $(this).form('validate');
      if(isValid){
        alert('true');
    }else {
    alert('false');
   }
});
Was it helpful?

Solution

Following lines of code will do the trick.

For validatebox:

$('#Field ID').validatebox('disableValidation');

For numberbox:

$('#Field ID').numberbox('disableValidation');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top