cerebral-legacy / cerebral-module-forms Goto Github PK
View Code? Open in Web Editor NEWForm handling for Cerebral
Home Page: http://cerebral-website.herokuapp.com/documentation/cerebral-module-forms
License: MIT License
Form handling for Cerebral
Home Page: http://cerebral-website.herokuapp.com/documentation/cerebral-module-forms
License: MIT License
The async demo is not working. In the react/input we do not call the onBlur function. Needs to be fixed.
We should add documentation on dependents validation.
Sometimes you need to know what field or fields that is invalid. This can be used to highlight scroll to input or any other reason #
in actions/validateForm line 32 36
var isValid = result.isValid && !isRequired(field);
errorMessage: isValid ? null : field.errorMessages[result.failedRuleIndex],
the result.failedRuleIndex is 0 if it pass.
we don't know which the error is.
The render
function of passes all its properties on to the element it creates:
https://github.com/cerebral/cerebral-module-forms/blob/master/react/Input/index.js#L31
Thus, also the property field
will be passed on the the HTML input element, which does not exist there, resulting in the warning:
Warning: Unknown prop
field
on tag. Remove this prop from the element. For details, see https://fb.me/react-unknown-prop
If we set up forms with isValue and pass parameter to it this error will occur.
rules[key] is not a function
form
name: {
value: [],
isValue: ['minLength:3']
}
The isValue needs to be parsed and also passed to the rule.
In helpers/rules.js we have this rule.
equalsField: function (value, form, field) {
return value == form[field];
},
Should this be return value === form[field].value?
We need to look at the actual response to make sure it's not just text. If we make a request to an api endpoint that does not exists it returns a String and will be Uncaught SyntaxError
when parsed as json.
Possible use case is to check the uniqueness of an email or username.
None of the demo projects seems to cover the use case of a form used for updating data, in all cases the 'value' of each field is set when the form is added to state. To make it work I am using code along the following lines in an action when the update form (teamInputForm) is opened:
const {teams, selectedId} = state.get();
const {id, name} = teams[selectedId];
state.set(['teamInputForm', 'id', 'value'], id);
state.set(['teamInputForm', 'name', 'value'], name);
Is this the best way to approach this? I'm happy to contribute an update form example to the demos if anyone can confirm the best approach.
Thanks, Colin
Hi, I'm assuming isTouched
is to determine whether or not the form field is dirty or not. So, when the end user modifies the input so that it no longer matches the default value, then isTouched = true
If the above is correct, it doesn't seem to be working. If the default value is "" then isTouched is always false. When default value is set to some string like "foo" then isTouched is always true.
Using "cerebral-module-forms": "^0.2.7"
Looks like any extra support (focus control, debounced validation, etc) requires to build own chains and register it in app level.
Currently index.js is very simple and in fact could be not used at all, if you decide to build your own chains.
Maybe we should better provide actions, factories, uttilities, etc in cerebral-forms
package without module. We still can have cerebral-module-forms
with default setup as easy start point.
I think we need a better way to handle isValid.
If a field is not required and has no value, we should not run the validations as all and isValid=true&errorMessage=null.
Otherwise, always run the validations when a field is added or its value is updated.
React 15 complains about controlled and uncontrolled inputs. We can not have defaultValue and value in the inputs. Since cerebral is controlling the input we should remove defaultValue from the demo so we don't get all the warnings in the console.
Right now there is no way to provide an error message for a required field if it has no valid.
Hi, not sure if this is a desired behavior or not, but, if the isNumeric
rule is passed NaN
, it will return true. Technically, in the javascript world, this is working properly, but, in human terms, I think that it should return false for NaN
. Thoughts?
@christianalfoni In the helpers folder isValidForm and isValidatingForm only has one diff on line 12. Maybe we could remove one of them and merge?
Cerebral supports dot notation for setting state but the forms module does not.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.