Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
error on the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanflorentin committed Aug 6, 2016
1 parent 4cfe41e commit 17500c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ export default function (compDef) {

for (let fieldName of fieldNames) {
const componentField = compDef.fields[fieldName]
const field = <Input key={fieldName} value={next[fieldName] ||''}
const fieldError = `${fieldName}Error`
let error = ''
if (next[fieldError]) {
error = <span>{next[fieldError]}</span>
}
const field = <div key={fieldName}>
<Input value={next[fieldName] ||''}
type={componentField.uiType} label={componentField.label} name='name' icon='assignment'
onChange={(e) => {
next[fieldName] = e
save()
}}/>
{error}
</div>
listFields.push(field)
}

Expand Down
2 changes: 2 additions & 0 deletions src/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ export default function (compDef) {
const value = String(action.component[fieldName])
const validators = fields[fieldName].validate
if (validators && validators.length > 0) {
let validatorPassed = true
for (let validator of validators) {
const valid = validator.func(value, validator.params)
if (!valid) {
next.isValid = false
next[`${fieldName}Error`] = validator.message
}
else {delete next[`${fieldName}Error`]}
}
}
}
Expand Down

0 comments on commit 17500c3

Please sign in to comment.