Using an input=“submit” field to submit instead of button=“” with parsley.js

喜欢而已 提交于 2019-12-02 20:13:47

问题


I currently have an ASP.net page which has one form tag around the entire page. Within that page, I have two forms that are validated with parsley.js when their respective submit button is clicked. At the moment, the trigger to validate these forms are buttons and I need for them to be input="submit". Does anyone have an idea on how to execute this?

Here's a JS fiddle example - http://jsfiddle.net/ukgvam9k/26/

<form method='post' id='form'>
<div class="first">
    <input type='text' id='firstname' name='firstname' data-parsley-group="first" required />
    <input type='text' id='lastname' name='lastname' data-parsley-group="first" required />
    <input type='text' id='phone' name='phone' data-parsley-group="first" required />
    <button type="button" id="submit-form">Submit</button>
</div>

<div class="secon">
    <input type='text' id='thisisrequired' name='thisisrequired' data-parsley-group="second" required />
    <button type="button" id="submit-form2">Submit 2</button>
</div>  

$("#submit-form").on('click', function () {
$('#form').parsley().validate("first");
if ($('#form').parsley().isValid("first")) {

    $('#form').parsley().destroy();
     console.log('valid');
     //$('#form').submit();
} else {
    console.log('not valid');
}});

$("#submit-form2").on('click', function () {
$('#form').parsley().validate("second");
if ($('#form').parsley().isValid("second")) {
    $('#form').parsley().destroy();
    console.log('valid');
} else {
    console.log('not valid');
}});

回答1:


@Learner again came to the rescue! Here's his fiddle - js.fiddle

<div></div>


来源:https://stackoverflow.com/questions/31290192/using-an-input-submit-field-to-submit-instead-of-button-with-parsley-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!