guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.05k stars 1.32k forks source link

ROR adding data-parsley-multiple attribute to input checkbox, over riding user provided value. #1004

Closed varghesethomase closed 8 years ago

varghesethomase commented 8 years ago

I had a form, where i had given data-parsley-multiple attribute to a specific value. But rails automatically sets it to same that of the id attribute. And the real mess is that, it happens only to a specific portion of form and rest all sections with different data-parsley-multiple value works fine.

.form-group = f.check_box :kyc_shops_and_establishment_cert,'data-parsley-mincheck' => '1', 'data-parsley-multiple' => 'spbproof', 'data-parsley-group' => 'solepropbusinessproof', 'data-parsley-trigger' => 'click', class: 'kyc_checkbox' | &nbsp;&nbsp; = f.label :kyc_shops_and_establishment_cert, 'Shops and Establishment Certificate / Goumasta License (Preferred)' compiles to <div class="form-group parsley-success"><input name="merchant_request[kyc_shops_and_establishment_cert]" value="0" type="hidden"><input data-parsley-id="9562" data-parsley-multiple="merchant_requestkyc_shops_and_establishment_cert" data-parsley-mincheck="1" data-parsley-group="solepropbusinessproof" data-parsley-trigger="click" class="kyc_checkbox" value="1" name="merchant_request[kyc_shops_and_establishment_cert]" id="merchant_request_kyc_shops_and_establishment_cert" type="checkbox">&nbsp;&nbsp;<label for="merchant_request_kyc_shops_and_establishment_cert">Shops and Establishment Certificate / Goumasta License (Preferred)</label></div>

marcandre commented 8 years ago

I don't understand. There's just no way Rails will change anything to the data-parsley-multiple you are giving it. Did you check View Page Source (Chrome) or equivalent?

varghesethomase commented 8 years ago

What i have given in the second code snippet is the output what browser renders. And the first one is the raw slim file. 'data-parsley-multiple' => 'spbproof', in slim gets converted to data-parsley-multiple="merchant_requestkyc_shops_and_establishment_cert".

marcandre commented 8 years ago

If you look at what the browser renders, there's a zillion things that might have changed the attribute. Your JS code, Parsley's, or something else.

I simply can't see how it could be possible that the slim source you provided would output the HTML you have.

What's the HTML source actually returned from the server?

marcandre commented 8 years ago

Let me know if this is still an issue, and if so produce a CodePen with an example. Thanks.

Zogoo commented 2 years ago

@marcandre issue is still there. I think it's because you guys has some default value setter for checkbox and raido buttons,

      if (name) {
        $('input[name="' + name + '"]').each(function (i, input) {
          var type = Utils.getType(input);
          if (type === 'radio' || type === 'checkbox') input.setAttribute(_this.options.namespace + 'multiple', _this.options.multiple);
        });
      } // Check here if we don't already have a related multiple instance saved

Official url

I had to rewrite data_parsley_multiple when On load document. To make work validation that checks minimum check of check boxes.