2

I have a form that is using Model Validation, however I need to ask the user a question that only gets asked when the model state is valid and if the user has not changed a value on the form, therefore the user has not changed a default value.

Is it possible that a message can appear on screen to ask the user to confirm (only when model state is valid), No to prevent the form from submitting and agreeing to yes will allow the form to submit?

2 Answers 2

1

You could handle the forms .submit() and test if .valid() and display a confirm dialog

$('form').submit(function() {
  if ($(this).valid()) {
    if (!confirm('Do you accept ...')) {
      return false; // cancel the submit
    }
  }
});
Sign up to request clarification or add additional context in comments.

Comments

0

Many thanks to Stephen Muecke for his solution. I have modified as follows:

$('form').submit(function() {
    var checkValue = document.getElementById('amount').value;

    if (checkValue == 10000) {
        if ($(this).valid()) {
            if (!confirm('The amount you are applying for is £10000, are you happy with this amount?')) {
                return false;
            }
        }
    }
});

Many thanks Stephen :-)

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.