Custom Fields
Re-Envisioned
Support MB Frontend Submission Validation does not work when field is clonable

This topic contains 2 replies, has 2 voices, and was last updated by  calpaq 6 months, 1 week ago.

  • Creator
    Topic
  • #14521

    calpaq
    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #14530

    Anh 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

    calpaq
    Participant

    Thank you Tran
    Regards,
    Calpaq

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.