Validation does not work when field is clonable

Support MB Frontend Submission Validation does not work when field is clonable

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #14521
    calpaqcalpaq
    Participant

    Hi Tran,
    I just found the same question asked before 1 year in general section but that seems closed thats why I am asking the same question again because my requirement is same now & validation for cloned field need to work.My problem is little different than previous discussion, there you said it breaks because of changing ID's so I have built my validation on the name attribute but in vain can you please help me?

    The following function only works on first row but fails/no action on cloned rows

    
    $("input[name$='fill-time\]'], input[name$='peak-pressure\]']" ).on("focusout", function (){
          viscosity = 0.0;
          shear_rate = 0.0;
    
          ins_ratio = $("#fm-intensification-ratio").val();
          fill_time = $(this).closest(".rwmb-row").find("input[name$='fill-time]']").val();
          pk_inj_press = $(this).closest(".rwmb-row").find("input[name$='peak-pressure]']").val();
          viscosity = parseFloat(ins_ratio) * parseFloat(fill_time) * parseFloat(pk_inj_press);
          viscosity = parseInt(viscosity,10);
          shear_rate = parseFloat(1 / parseFloat(fill_time)).toFixed(4);
    
          $(this).closest(".rwmb-row").find("input[name$='viscosity]']").val(viscosity);
          $(this).closest(".rwmb-row").find("input[name$='shear-rate]']").val(shear_rate);
          
      } );
    

    Thanks & Regards,
    Calpaq

    #14530
    Anh TranAnh Tran
    Keymaster

    Hi Calpaq,

    The problem is the jQuery selector $("input[name$='fill-time\]'], input[name$='peak-pressure\]']" ). It's static, while cloning creates new elements.

    To fix that, you need to listen to a higher element, such as body, like this:

    $( 'body' ).on("focusout", "input[name$='fill-time\]'], input[name$='peak-pressure\]']", function (){} );

    #14539
    calpaqcalpaq
    Participant

    Thank you Tran
    Regards,
    Calpaq

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.