
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
ember-base-form-validation
Advanced tools
Very simple validation using components and validation models
Simple ember component based form validation module , only providing base structure and components for validation . His goal is to be flexible and adaptive to any situation.
:warning: This addon does not provide any types validation methods or checks.
ember install ember-base-form-validation
The validation form is the base of the validation , it must contain a @schema
attribute in order to provide validation to the inputs.
userform.hbs
<ValidationForm @validateOnInit={{false}} class="form" @schema={{this.validation}} as |form|>
</ValidationForm>
@schema
(required) : a Validation schema
for the children inputs@validateOnInit
(optional) : a boolean
to tell the form to validate or not all the children on init.any html attributes
(optional)validate
: runs the validation for all the childrenisDirty
(boolean
) : returns if the form is dirty (any field has been validated)hasErrors
(boolean
) : returns if the form validator has errorsvalidating
(boolean
) : returns if the form validator is running validations (for async).The validation input is an HTML input who validates its value after some events had been triggered.
<ValidationForm class="form" @schema={{this.validation}} as |form|>
<ValidationInput @validation="username" @validateOn="change" name="username" @parent={{form}} as |i|>
{{#if i.error}}
<p>{{i.error}}</p>
{{/if}}
</ValidationInput>
<ValidationInput @validation="email" @validateOn="focus" name="email" @parent={{form}} as |i|>
{{#if i.error}}
<p>{{i.error.message}} for {{i.error.field}}</p>
{{/if}}
</ValidationInput>
<input type="submit" disabled={{form.hasErrors}} {{on "click" this.submit}} value="submit">
</ValidationForm>
@parent
(BaseValidationFormComponent
) (required) : the parent form.@validation
(string
) (required) : Tell which validation the validator must use to validate the input value.@validateOn
(string
) (optional) : an html event to tell the input when to launch its validation.@alone
(boolean
) (optional) : disable the validation , @parent
and @validation
attributes become optional.any html attributes
(optional)validate
: runs the validation for the inputisDirty
(boolean
) : returns if the input value is dirty (has been validated)error
(any
) : error associated to the input (null
if no error)The validation schema checks if the current value of the input is correct , otherwhise it returns any value indicating there's an error for the field.
If it returns null
or undefined
, the value is correct.
The method can be async or sync.
import validator from 'validator'; // external validation module
import { BaseValidator , validationProperty } from 'ember-base-form-validation';
export class UserValidator extends BaseValidator {
@validationProperty()
username(str) {
if (!validator.isLength(str,{
min : 10
})) {
return 'Lenght must be less than 10 characters';
}
}
@validationProperty()
async email(str) {
if (!validator.isEmail(str)) {
return { // can return in any format you want
message : 'Email not valid',
field : 'email'
};
}
}
}
@validationProperty(ignoreUndefined = true)
indicates that the method is a validation method. The parameter ignoreUndefined
converts the input value to a null string if it's undefined.
errors
object
: errors of the validatorcontext
any
: context passed by the constructorwaitAndCheckErrors
(Promise<boolean>
) : wait for the validator to finish validation and returns if it contains errors.
hasErrors
(boolean
) : returns if validator has errors
isDirty
(boolean
) : returns if validator has validated this field at least once
validationRunning
(boolean
) : returns if validator is running async tasks.
import Component from '@glimmer/component';
import { UserValidator } from '../validation/user';
import { action } from '@ember/object';
export default class UserFormComponent extends Component {
validation;
constructor(...args) {
super(...args);
this.validation = new UserValidator(this);
}
@action
submit(t) {
this.validation.waitAndCheckErrors().then( (hasErrors) => {
if (hasErrors) {
return;
}
// do your job
}
}
}
Same as above except for the template. Custom Input let you define you own input to bind the value to and validate.
userform.hbs
<ValidationForm @validateOnInit={{true}} @schema={{this.validation}} as |form|>
<ValidationInputCustom @parent={{form}} @validation="username" @value={{@model.username}} as |i|>
<Input type="text" name="username" @value={{i.value}} {{on "change" i.validate}} />
{{#if i.error}}
<p>{{i.error}}</p>
{{/if}}
</ValidationInputCustom>
<ValidationInputCustom @parent={{form}} @validation="email" @value={{@model.email}} as |i|>
<Input type="text" name="email" @value={{i.value}} {{on "change" i.validate}} />
{{#if i.error}}
<p>{{i.error}}</p>
{{/if}}
</ValidationInputCustom>
{{#if form.validating}}
<p>Validating...</p>
{{else}}
<input type="submit" disabled={{form.hasErrors}} {{on "click" this.submit}} value="submit">
{{/if}}
</ValidationForm>
You can inherit BaseValidationInputComponent
class to make your custom input component and BaseValidationFormComponent
to make your own validation form
myinput.js
import { action } from '@ember/object';
import { BaseValidationInputComponent } from 'ember-base-form-validation';
export default class MyinputComponent extends BaseValidationInputComponent {
constructor() {
super(...arguments);
console.log("Init custom");
}
@action
validate() {
super.validate();
console.log("Validate " + this.name);
}
}
myform.js
import { action } from '@ember/object';
import { BaseValidationFormComponent } from 'ember-base-form-validation';
export default class MyformComponent extends BaseValidationFormComponent {
constructor() {
super(...arguments);
console.log("Init custom");
}
@action
validate() {
super.validate();
console.log("Validate all");
}
}
:exclamation: I'm new to EmberJS community , don't hesitate to contribute !
See the Contributing guide for details.
This project is licensed under the MIT License.
FAQs
Very simple validation using components and validation models
The npm package ember-base-form-validation receives a total of 0 weekly downloads. As such, ember-base-form-validation popularity was classified as not popular.
We found that ember-base-form-validation demonstrated a not healthy version release cadence and project activity because the last version was released 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.