2

hello I have this field in checkout, I would like use 'mage/validation' to verify if the is true or not.

I tried, but it doesn't work, maybe I didn't understand how it works :

let password = $('[for="customer-password"]').next().find('.input-text').validation('isValid')
console.log(password)

MY HTML

<div class="field amcheckout-password required" data-bind="fadeVisible: isPasswordVisible, css: {required: isPassword}"
    style="display: block;"> <label class="label" for="customer-password" style="top: 16px; font-size: 16px;"> <span
            data-bind="i18n: 'Password'">Mot de passe</span></label>

    <input class="input-text mage-error" type="password" name="password" id="customer-password">

</div>

Also I added a button

<div class="buttonContinue buttonContinueStepOne"> Continuer</div>

With his js

$('.buttonContinueStepOne').click(function(){
    console.log('nextstep')
})

1 Answer 1

0

Add data-validation to the password input field

data-validate="{required:true, 'isValid':true}

So when based on isValid function it will validate the password

Try this

<input class="input-text mage-error" type="password" name="password" data-validate="{required:true, 'isValid':true}" id="customer-password">

UPDATE:

Make this disabled by default:

<div class="buttonContinue buttonContinueStepOne" disabled>Continuer</div>

Then add the below code, where condition is if your validation return true

let password = document.getElementsByClassName('buttonContinue');
password.disabled = false;
6
  • I appended a button with jquery, is it possible to disable this button if form is not valid ?
    – Kevin ami
    Nov 3, 2022 at 9:29
  • Can you please share the code Nov 3, 2022 at 9:31
  • I added in the main post
    – Kevin ami
    Nov 3, 2022 at 9:44
  • @Kevinami Updated the answer Nov 3, 2022 at 9:56
  • ok, but How do you verify if it's true or not , just using this ? $('.myformclass').validation('isValid')
    – Kevin ami
    Nov 3, 2022 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.