
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
mobx-react-form
Advanced tools
A.K.A.
mobx-ajv-form
(deprecated). Usemobx-react-form
instead.
See the Changelog or the Documentation for all the details.
npm install --save mobx-react-form
https://mobx-react-form-demo-zgltrpjjwi.now.sh/
const fields = {
username: {
label: 'Username',
value: 'SteveJobs'
},
email: {
label: 'Email',
value: 's.jobs@apple.com'
},
password: {
label: 'Password',
value: 'thinkdifferent'
}
};
Below we are creating a plugins
object using the validatorjs
package to enable DVR
functionalities (Declarative Validation Rules).
See Validation Plugins and Supported Validation Packages for more info.
import validatorjs from 'validatorjs';
const plugins = { dvr: validatorjs };
Simply pass the fields
and plugins
objects to the constructor
import Form from 'mobx-react-form';
export default new Form({ fields, plugins });
Now define a rules
property on the form fields as shown here.
import React from 'react';
import { observer } from 'mobx-react';
const FormComponent = ({ form, events }) => (
<form>
<input
type="text"
name={form.$('username').name}
value={form.$('username').value}
placeholder={form.$('username').label}
onChange={form.$('username').sync}
/>
<p>{form.$('username').error}</p>
...
<button
type="submit"
disabled={!form.isValid}
onClick={events.handleOnSubmit}
>Submit</button>
<button
type="submit"
onClick={events.handleOnReset}
>Reset</button>
<button
type="submit"
onClick={events.handleOnClear}
>Clear</button>
<p>{form.error}</p>
</form>
);
export default observer(FormComponent);
form.$('fieldkey')
is a shortcut toform.fields.fieldkey
handleOnSubmit = (e) => {
e.preventDefault();
form.validate()
.then((isValid) => isValid
? onSuccess()
: onError());
};
onError() {
// get all form errors
console.log('All form errors', form.errors());
// invalidate the form with a custom error message
form.invalidate('This is a generic error message!');
}
onSuccess() {
alert('Form is valid! Send the request here.');
// get field values
console.log('Form Values!', form.values());
}
handleOnClear = (e) => {
e.preventDefault();
// clear the form
form.clear();
}
handleOnReset = (e) => {
e.preventDefault();
// reset to the default initial values
form.reset();
}
If you want to contribute to the development, do not hesitate to fork the repo and send pull requests.
And don't forget to star the repo, I will ensure more frequent updates! Thanks!
FAQs
Reactive MobX Form State Management
The npm package mobx-react-form receives a total of 7,102 weekly downloads. As such, mobx-react-form popularity was classified as popular.
We found that mobx-react-form demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.