ソースを参照

#287: Only send the submit button which is clicked. Improve #238

nghuuphuoc 11 年 前
コミット
cbfecf255e

+ 1 - 0
CHANGELOG.md

@@ -10,6 +10,7 @@
 * [#275](https://github.com/nghuuphuoc/bootstrapvalidator/issues/275): Add ```destroy()``` method
 * [#274](https://github.com/nghuuphuoc/bootstrapvalidator/pull/274): Fix feedback icons in ```input-group```, thanks to [@tiagofontella](https://github.com/tiagofontella)
 * [#282](https://github.com/nghuuphuoc/bootstrapvalidator/issues/282): Use error message that is returned from [```callback```](http://bootstrapvalidator.com/validators/callback/), [```remote```](http://bootstrapvalidator.com/validators/remote/) validators
+* [#287](https://github.com/nghuuphuoc/bootstrapvalidator/issues/287): Only send the submit button which is clicked. It's an enhancement for [#238](https://github.com/nghuuphuoc/bootstrapvalidator/issues/238)
 
 ## v0.4.5 (2015-05-15)
 

+ 1 - 0
demo/index.html

@@ -177,6 +177,7 @@
                         <div class="form-group">
                             <div class="col-lg-9 col-lg-offset-3">
                                 <button type="submit" class="btn btn-primary" name="signup" value="Sign up">Sign up</button>
+                                <button type="submit" class="btn btn-primary" name="signup2" value="Sign up 2">Sign up 2</button>
                                 <button type="button" class="btn btn-info" id="validateBtn">Manual validate</button>
                                 <button type="button" class="btn btn-info" id="resetBtn">Reset form</button>
                             </div>

+ 10 - 11
dist/js/bootstrapValidator.js

@@ -236,17 +236,6 @@
                             $field.attr('data-bv-field', field);
                             options.fields[field] = $.extend({}, opts, options.fields[field]);
                         }
-                    })
-                    .end()
-                // Create hidden inputs to send the submit buttons
-                .find(this.options.submitButtons)
-                    .each(function() {
-                        $('<input/>')
-                            .attr('type', 'hidden')
-                            .attr('data-bv-submit-hidden', '')
-                            .attr('name', $(this).attr('name'))
-                            .val($(this).val())
-                            .appendTo(that.$form);
                     });
 
             this.options = $.extend(true, this.options, options);
@@ -931,6 +920,16 @@
          * It might be used when you want to submit the form right inside the submitHandler()
          */
         defaultSubmit: function() {
+            if (this.$submitButton) {
+                // Create hidden input to send the submit buttons
+                $('<input/>')
+                    .attr('type', 'hidden')
+                    .attr('data-bv-submit-hidden', '')
+                    .attr('name', this.$submitButton.attr('name'))
+                    .val(this.$submitButton.val())
+                    .appendTo(this.$form);
+            }
+            // Submit form
             this.$form.off('submit.bv').submit();
         },
 

ファイルの差分が大きいため隠しています
+ 2 - 2
dist/js/bootstrapValidator.min.js


+ 10 - 11
src/js/bootstrapValidator.js

@@ -235,17 +235,6 @@
                             $field.attr('data-bv-field', field);
                             options.fields[field] = $.extend({}, opts, options.fields[field]);
                         }
-                    })
-                    .end()
-                // Create hidden inputs to send the submit buttons
-                .find(this.options.submitButtons)
-                    .each(function() {
-                        $('<input/>')
-                            .attr('type', 'hidden')
-                            .attr('data-bv-submit-hidden', '')
-                            .attr('name', $(this).attr('name'))
-                            .val($(this).val())
-                            .appendTo(that.$form);
                     });
 
             this.options = $.extend(true, this.options, options);
@@ -930,6 +919,16 @@
          * It might be used when you want to submit the form right inside the submitHandler()
          */
         defaultSubmit: function() {
+            if (this.$submitButton) {
+                // Create hidden input to send the submit buttons
+                $('<input/>')
+                    .attr('type', 'hidden')
+                    .attr('data-bv-submit-hidden', '')
+                    .attr('name', this.$submitButton.attr('name'))
+                    .val(this.$submitButton.val())
+                    .appendTo(this.$form);
+            }
+            // Submit form
             this.$form.off('submit.bv').submit();
         },