lundi 16 novembre 2020

laravel validation, how to add validation rule on client side?

//html code
<form>
<input type="radio" id="defult" name="price_type" value="default">
<label for="defult">Default Price</label><br>
<input type="radio" id="custom" name="price_type" value="custom">
<label for="custom">Custom Price</label><be>

<input placeholder="Custom Price" class="form-control" name="custom_price">
</form>

$('input[type=radio][name=price_type]').change(function() {
    if (this.value == 'default') {
        //make custom_price optional
    }
    else if (this.value == 'custom') {
        //make custom_price required
    }

});

Actually, I have a radio box for the custom price or default price, if the user selects the custom price then want to make input[name=custom_price] required or if the user selects default price then make input[name=custom_price] optional.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire