M
M
mishapsv2016-05-01 15:50:15
React
mishapsv, 2016-05-01 15:50:15

Why might preventDefault not work?

Help find the cause.
Here is the code In the Add component for onBtnClickHandler preventDefault does not work and the code as a whole.
Probably the reason is obvious, but I don't see it point-blank.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aves, 2016-05-01
@mishapsv

A button inside a form is of type submit by default, and it is the form's event that fires accordingly. The easiest way is to add an onSubmit handler to the form element.
Another option is to add type='button' to the button element. But it seems that disabling disabled on a DOM element does not turn on the component, you need to call render again, and therefore you will have to redo the checkbox logic to connect it to the button through the state of the component, like <button disabled={this.state.checkrule}>
In the case of type='button', there is no need for preventDefault at all, the default action is not will.
In general, preventDefault doesn't fire because onClick doesn't fire. It works with getting disabled from state .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question