0

disable the button when form is not validated.

{N} Playground

A similar question was asked before. It says it's solved but what exactly was the decent solution? Did I miss something?

Form validation documentation page is broken it has markdown errors.

Community
  • 1
  • 1
Cem Kaan
  • 2,086
  • 1
  • 24
  • 55

2 Answers2

1

I answered the other question.

I have also updated your playground.

Ian MacDonald
  • 13,472
  • 2
  • 30
  • 51
  • Multiple input version of this solution is [in this {N} Playground](https://play.nativescript.org/?template=play-vue&id=P4HCCn&v=19) As you recommended in slack, I will Leave the button enabled, but then do something different if hasValidationErrors(). Thank you – Cem Kaan May 14 '20 at 17:06
1

Add a @propertyValidated="onValidateForm" event listener that triggers on each validation. Then you can use hasValidationErrors() on the form to see if the form is valid. The only trick is that is has to be wrapped in a setTimeout(), like so:

onValidateForm(event) {
    setTimeout(() => {
        this.validated = !event.object.hasValidationErrors();
        console.log("form valid: " + this.validated);
    }, 100);
}

For a complete solution, see this {N} Playground.

Cem Kaan
  • 2,086
  • 1
  • 24
  • 55
Tiago A.
  • 2,568
  • 1
  • 22
  • 27
  • Even if it is using that crappy `setTimeout`, I think this solution is better than @ian-macdonald's because it will work no matter how many fields you have. – Tiago A. May 14 '20 at 16:08