Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fuelux wizard validation input

I have made a form nested inside the fuelux wizard. The bookstrap required field will not show up if the person clicks the next button. Is there any methods which can make it a requirement that the user cannot progress by clicking next until the required fields have been entered?

Here is an example of the input

  <tr>
  <td>3</td>
    <td><label class="control-label" for="inputCompanyCountry">Country <span style="color:red">*</span></label></td>
    <td><div class="controls controls-extra"><input type="text" id="inputCompanyCountry" name="inputCompanyCountry" value=""required></div></td>
    <td><div class="help-inline">Country of residence</div></td>
  </tr>

The scripts used for the next and previous buttons

$(function() {
$('#MyWizard').on('change', function(e, data) {
    console.log('change');
    if(data.step===3 && data.direction==='next') {
        // return e.preventDefault();
    }
});

$('#MyWizard').on('changed', function(e, data) {
    console.log('changed');
});
/*$('#MyWizard').on('finished', function(e, data) {
    console.log('finished');
});*/
$('#btnWizardPrev').on('click', function() {
    $('#MyWizard').wizard('previous');
});
$('#btnWizardNext').on('click', function() {
    $('#MyWizard').wizard('next','foo');
});


$('#btnWizardStep').on('click', function() {
    var item = $('#MyWizard').wizard('selectedItem');
    console.log(item.step);
});
});
like image 468
James R Avatar asked Aug 07 '13 17:08

James R


2 Answers

what i did:

$('#MyWizard').on('change', function(e, data) {
    var isValid = $('#stepId [required]').valid();
    if (data.direction === 'next' && !isValid) {
        e.preventDefault();
    }
});

If you want to disable moving both ways, then just remove the data.direction ==='next' part.

like image 21
Rafael Herscovici Avatar answered Oct 18 '22 03:10

Rafael Herscovici


If you want to validate without sending the form, you can use jquery.validate. Use the method $("#form_id").valid();, it returns true or false depending the status of the form add class "required" to the inputs in question.

$('#MyWizard').on('change', function(e, data) {
    console.log('change');
    if(data.step===3 && data.direction==='next') {
        if($("#form_id").valid()){
            // allow change
        }else{
            // cancel change
        }
    }
});
like image 87
Birkto Avatar answered Oct 18 '22 03:10

Birkto