react-schema-form icon indicating copy to clipboard operation
react-schema-form copied to clipboard

validation behaviour on blur

Open Vaevictus opened this issue 8 years ago • 4 comments

Is there a way I can change the validation behavior? It seems to affect the demo page too. If I load a form, I can immediately save it without actually firing any validation. I also want to validation errors to immediately load (the red ones) when I initialize it. Only after entering some data then removing it with backspace will show the "this field is required" error for example.

Additionally, and I think this is a more generic question with regards to react, but still related:

if I have

<mycontainer >

<SchemaForm />

<MySubmitButton />

</mycontainer>

How can I make the mysubmitbutton check the validity of the form prior to allowing the submit, or even bind the enablement status of the button to the validity status of the form?

thanks

Vaevictus avatar Jan 22 '17 20:01 Vaevictus

These are all goog questions. The current released version should fire validation when the form is submitted. The demo is a little old. For the second question, do you have logic in your submit button? If not, you can use generated button. Otherwise, you csn call schema form api from you button.

stevehu avatar Jan 26 '17 12:01 stevehu

I have the same situation. This is my submit callback

sendCredentials: function(e) {
    e.preventDefault();
    let result = utils.validateBySchema(this.state.schema, this.state.model);  
    if (result.error !== null) {      
      console.log(result);     
    }
  },

It seems like a bug - if I submit form with incorrect fields, validation fires and I see this in console, but there are no indication at wrong fields in form

alexey-kuznetsov avatar Apr 19 '17 10:04 alexey-kuznetsov

@alexey-kuznetsov From what you have describe it is a bug. I will try to reproduce and get it fixed. Thanks for your help.

stevehu avatar Apr 23 '17 01:04 stevehu

@stevehu embedded validation doesn't prevent form from submitting. It is not normal.

alexey-kuznetsov avatar Apr 23 '17 06:04 alexey-kuznetsov