Home Show validation after iterating through input name
Reply: 0

Show validation after iterating through input name

user2443
1#
user2443 Published in April 19, 2018, 10:00 am

I have following values:

parent input value:

<input type="text" id="due_interval" name="maintenance_template[due_interval]" value="2">
<input type="hidden" id="parent_due_interval_type_id"  name="maintenance_template[due_interval_type_id]" value="2">

sub input values:

<input type="hidden" name="sub_maintenance_template[1][due_interval]" value="2" id="subtask_due_interval">
<input type="hidden" name="sub_maintenance_template[1][due_interval_type]" value="3" id="due_interval_type_id">
<input type="hidden" name="sub_maintenance_template[2][due_interval]" value="20" id="subtask_due_interval">
<input type="hidden" name="sub_maintenance_template[2][due_interval_type]" value="2" id="due_interval_type_id">
<input type="hidden" name="sub_maintenance_template[3][due_interval]" value="5" id="subtask_due_interval">
<input type="hidden" name="sub_maintenance_template[3][due_interval_type]" value="2" id="due_interval_type_id">

parent_due_interval_type_id can be either 2 or 3. 2 is for hours. 3 is for days. If we select 3 then it should convert due_interval value to hrs ( by multiplying with 24). Now I want to show validation by checking that sub input values should be less than parent input values.Validation message should appear only once.

My trial:

subdueIntervalTypeId = Number( $('#frm_add_edit_sub_maintenance_template #due_interval_type_id').val());
    parentDueIntervalTypeId = Number( $('#parent_due_interval_type_id').val());
    if( 3 == parentDueIntervalTypeId ) {
        parentDueTime = Number( $('#due_interval').val()) * 24;
    } else { 
        parentDueTime = Number( $('#due_interval').val());
    }
    if( 3 == subdueIntervalTypeId ) {
        subtaskDueTime = Number( $('#frm_add_edit_sub_maintenance_template #subtask_due_interval').val()) * 24;
    } else { 
        subtaskDueTime = Number( $('#frm_add_edit_sub_maintenance_template #subtask_due_interval').val());
    }

    if( parentDueTime <= subtaskDueTime ) {
            $('#error_div .error').append(' <i></i> Due Time for sub-task should be less than or equal to Due Time for parent task.');
            $('#error_div .error').show();
            boolIsValid = false;
        }

Should I need to iterate through name attribute or id for sub input values?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.300514 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO