Skip to content

Commit 1e919cf

Browse files
committed
Phenome Input: support to force error message
Fixes framework7io/framework7-vue#348
1 parent a5e4c72 commit 1e919cf

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/phenome/components/input.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export default {
4646

4747
// Error, Info
4848
errorMessage: String,
49+
errorMessageForce: Boolean,
4950
info: String,
5051

5152
// Components
@@ -92,6 +93,7 @@ export default {
9293
resizable,
9394
clearButton,
9495
errorMessage,
96+
errorMessageForce,
9597
info,
9698
wrap,
9799
style,
@@ -110,6 +112,7 @@ export default {
110112
type === 'textarea' && resizable && 'resizable',
111113
!wrap && className,
112114
(noFormStoreData || noStoreData) && 'no-store-data',
115+
errorMessage && errorMessageForce && 'input-invalid'
113116
);
114117
let input;
115118
if (process.env.COMPILER === 'react') {
@@ -145,7 +148,7 @@ export default {
145148
validate={typeof validate === 'string' && validate.length ? validate : undefined}
146149
data-validate={validate === true || validate === '' ? true : undefined}
147150
tabIndex={tabindex}
148-
data-error-message={errorMessage}
151+
data-error-message={errorMessageForce ? undefined : errorMessage}
149152
className={inputClassName}
150153
onFocus={self.onFocusBound}
151154
onBlur={self.onBlurBound}
@@ -182,7 +185,7 @@ export default {
182185
validate={typeof validate === 'string' && validate.length ? validate : undefined}
183186
data-validate={validate === true || validate === '' ? true : undefined}
184187
tabIndex={tabindex}
185-
data-error-message={errorMessage}
188+
data-error-message={errorMessageForce ? undefined : errorMessage}
186189
className={inputClassName}
187190
onFocus={self.onFocusBound}
188191
onBlur={self.onBlurBound}
@@ -254,6 +257,9 @@ export default {
254257
return (
255258
<div id={id} ref="wrapEl" className={wrapClasses} style={style}>
256259
{inputEl}
260+
{errorMessage && errorMessageForce && (
261+
<div className="item-input-error-message">{errorMessage}</div>
262+
)}
257263
{clearButton &&
258264
<span className="input-clear-button" />
259265
}

src/phenome/components/list-item-content.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default {
4040
hasInput: false,
4141
hasInlineLabel: false,
4242
hasInputInfo: false,
43+
hasInputErrorMessage: false,
4344
};
4445
},
4546
render() {
@@ -77,6 +78,7 @@ export default {
7778
let hasInput = itemInput || self.state.hasInput;
7879
let hasInlineLabel = inlineLabel || self.state.hasInlineLabel;
7980
let hasInputInfo = itemInputWithInfo || self.state.hasInputInfo;
81+
let hasInputErrorMessage = self.state.hasInputErrorMessage;
8082

8183
const slotsContentStart = [];
8284
const slotsContent = [];
@@ -125,6 +127,7 @@ export default {
125127
if (tag === 'F7Input') {
126128
hasInput = true;
127129
if (child.props && child.props.info) hasInputInfo = true;
130+
if (child.props && child.props.errorMessage && child.props.errorMessageForce) hasInputErrorMessage = true;
128131
}
129132
if (tag === 'F7Label') {
130133
if (child.props && child.props.inline) hasInlineLabel = true;
@@ -135,6 +138,7 @@ export default {
135138
if (tag && tag.indexOf('f7-input') >= 0) {
136139
hasInput = true;
137140
if (child.data && child.data.info) hasInputInfo = true;
141+
if (child.data && child.data.errorMessage && child.data.errorMessageForce) hasInputErrorMessage = true;
138142
}
139143
if (tag && tag.indexOf('f7-label') >= 0) {
140144
if (child.data && child.data.inline) hasInlineLabel = true;
@@ -175,6 +179,12 @@ export default {
175179
} else if (!hasInputInfo) {
176180
self.hasInputInfoSet = false;
177181
}
182+
if (hasInputErrorMessage && !self.state.hasInputErrorMessage) {
183+
self.hasInputErrorMessageSet = true;
184+
self.setState({ hasInputErrorMessage });
185+
} else if (!hasInputInfo) {
186+
self.hasInputErrorMessageSet = false;
187+
}
178188
if (hasInlineLabel && !self.state.hasInlineLabel) {
179189
self.hasInlineLabelSet = true;
180190
self.setState({ hasInlineLabel });
@@ -336,6 +346,8 @@ export default {
336346
'item-input': hasInput,
337347
'inline-label': hasInlineLabel,
338348
'item-input-with-info': hasInputInfo,
349+
'item-input-with-error-message': hasInputErrorMessage,
350+
'item-input-invalid': hasInputErrorMessage,
339351
},
340352
Mixins.colorClasses(props),
341353
);
@@ -367,6 +379,7 @@ export default {
367379
const hasInlineLabel = $labelEl.hasClass('item-label-inline');
368380
const hasInput = $inputEl.length > 0;
369381
const hasInputInfo = $inputEl.children('.item-input-info').length > 0;
382+
const hasInputErrorMessage = $inputEl.children('.item-input-error-message').length > 0;
370383
if (!self.hasInlineLabelSet && hasInlineLabel !== self.state.hasInlineLabel) {
371384
self.setState({ hasInlineLabel });
372385
}
@@ -376,6 +389,9 @@ export default {
376389
if (!self.hasInputInfoSet && hasInputInfo !== self.state.hasInputInfo) {
377390
self.setState({ hasInputInfo });
378391
}
392+
if (!self.hasInputErrorMessageSet && hasInputErrorMessage !== self.state.hasInputErrorMessage) {
393+
self.setState({ hasInputErrorMessage });
394+
}
379395
},
380396
componentDidUpdate() {
381397
const self = this;
@@ -387,6 +403,7 @@ export default {
387403
const hasInlineLabel = $labelEl.hasClass('item-label-inline');
388404
const hasInput = $inputEl.length > 0;
389405
const hasInputInfo = $inputEl.children('.item-input-info').length > 0;
406+
const hasInputErrorMessage = $inputEl.children('.item-input-error-message').length > 0;
390407
if (hasInlineLabel !== self.state.hasInlineLabel) {
391408
self.setState({ hasInlineLabel });
392409
}
@@ -396,6 +413,9 @@ export default {
396413
if (hasInputInfo !== self.state.hasInputInfo) {
397414
self.setState({ hasInputInfo });
398415
}
416+
if (!self.hasInputErrorMessageSet && hasInputErrorMessage !== self.state.hasInputErrorMessage) {
417+
self.setState({ hasInputErrorMessage });
418+
}
399419
},
400420
methods: {
401421
onClick(event) {

0 commit comments

Comments
 (0)