Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 6839b4d

Browse files
committed
Adding behavior for noValidate and formNoValidate. Fixes #823
1 parent b648abb commit 6839b4d

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/components/control-component.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,15 @@ const propTypes = {
102102
persist: PropTypes.bool,
103103
getValue: PropTypes.func,
104104
isToggle: PropTypes.bool,
105+
106+
// HTML5 attributes
107+
formNoValidate: PropTypes.bool,
105108
};
106109

110+
const htmlAttributes = ['formNoValidate'];
111+
const disallowedPropTypeKeys = Object.keys(propTypes)
112+
.filter(key => htmlAttributes.indexOf(key) === -1);
113+
107114
const defaultStrategy = {
108115
get: _get,
109116
getFieldFromState,
@@ -320,10 +327,10 @@ function createControlClass(s = defaultStrategy) {
320327
getNodeErrors() {
321328
const {
322329
node,
323-
props: { fieldValue },
330+
props: { fieldValue, formNoValidate },
324331
} = this;
325332

326-
if (!node || (node && !node.willValidate)) {
333+
if (formNoValidate || !node || (node && !node.willValidate)) {
327334
this.willValidate = false;
328335
return null;
329336
}
@@ -637,7 +644,7 @@ function createControlClass(s = defaultStrategy) {
637644

638645
const finalControlProps = {
639646
...controlProps,
640-
...omit(props, Object.keys(propTypes)),
647+
...omit(props, disallowedPropTypeKeys),
641648
};
642649

643650
const modelString = getModel(model, state);

src/components/form-component.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ const propTypes = {
5353

5454
// standard HTML attributes
5555
action: PropTypes.string,
56+
noValidate: PropTypes.bool,
5657
};
5758

59+
const htmlAttributes = ['action', 'noValidate'];
60+
const disallowedPropTypeKeys = Object.keys(propTypes)
61+
.filter(key => htmlAttributes.indexOf(key) === -1);
62+
5863
const defaultStrategy = {
5964
get: _get,
6065
getForm,
@@ -305,12 +310,13 @@ function createFormClass(s = defaultStrategy) {
305310
handleIntents() {
306311
const {
307312
formValue,
313+
noValidate,
308314
} = this.props;
309315

310316
formValue.$form.intents.forEach((intent) => {
311317
switch (intent.type) {
312318
case 'submit': {
313-
if (isValid(formValue, { async: false })) {
319+
if (noValidate || isValid(formValue, { async: false })) {
314320
this.handleValidSubmit({ clearIntents: intent });
315321
} else {
316322
this.handleInvalidSubmit({ clearIntents: intent });
@@ -363,7 +369,7 @@ function createFormClass(s = defaultStrategy) {
363369
formValue,
364370
} = this.props;
365371

366-
const allowedProps = omit(this.props, Object.keys(propTypes));
372+
const allowedProps = omit(this.props, disallowedPropTypeKeys);
367373
const renderableChildren = typeof children === 'function'
368374
? children(formValue)
369375
: children;

0 commit comments

Comments
 (0)