Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
croud-forms
Advanced tools
A package for generating form inputs based on a JS object.
Install using yarn
yarn install croud-forms
Or if you're after the vue1 version.
yarn install croud-forms@1.0.6
And add to your Vue project as a plugin
import CroudForms from croud-forms
Vue.use(CroudForms)
Field object
The field object is made up of 3 mandatory keys and an additional contextual object that is needed for more complex fields, like select or cleave components.
{
data(){
return {
field: {
field_name: 'First name', // Sets the label text
field_type: 'text', // Type of field we want to use
field_slug: 'firstName', // Key of the data object to get and set
field_options: {
select_options: {
google_adwords: 'Google Adwords', // key: value
adwords_editor: 'Adwords Editor',
bing_ads: 'Bing Ads',
},
},
},
user: {
firstName: '',
},
}
},
}
Field components
Croud-forms provides two different components for displaying the form fields.
<!-- Form field component -->
<croud-form-field :field="field" v-model="user[field.field_slug]" />
<!-- Table row component -->
<table class="ui very basic table">
<tr is="croud-form-row" :field="field" v-model="user[field.field_slug]"></tr>
</table>
Croud-forms allows a read-only flag to be passed into any field as a prop
<croud-form-field :field="field" v-model="user.firstName" :read-only="true"/>
Croud-forms can integrate with vuelidate to provide visual feedback when the output of the form isn't what we expected.
You can add a validation object to your component which can dictate the rules for your fields, below is a very basic example, view the vuelidate docs for more inspiration.
import { validationMixin } from 'vuelidate'
import { required, minLength, numeric, email } from 'vuelidate/lib/validators'
export default {
mixins: [validationMixin],
validations: {
user: {
firstName: {
required,
minLength: minLength(2),
},
}
},
And for the visual feedback, you can pass the validation object through to the croud-form-field, like so...
<croud-form-field field="field" v-model="user.firstName" :validation="$v.user.firstName" />
This project includes a croud-form-builder component that can build a form based on a JSON schema and can also handle the validation
You can add this component to your mark up with the following syntax
<croud-form-builder :read-only="false" :schema='schema' v-model="user" :validations="$v.user" />
And you can build up your model, schema and validations from within your component.
import { validationMixin } from 'vuelidate'
import { required, minLength, numeric, email } from 'vuelidate/lib/validators'
export default {
mixins: [validationMixin],
data() {
return {
user: {
firstName: '',
lastName: '',
email: '',
age: 0,
},
schema: [
{
class: 'two fields',
children: [
{
field_name: 'First name',
field_type: 'text',
field_slug: 'firstName',
},
{
field_name: 'Last name',
field_type: 'text',
field_slug: 'lastName',
},
],
},
{
field_name: 'Email Address',
field_type: 'email',
field_slug: 'email',
},
{
field_name: 'Age',
field_type: 'number',
field_slug: 'age',
},
],
}
},
validations: {
user: {
firstName: {
required,
minLength: minLength(2),
},
lasstName: {
required,
minLength: minLength(2),
},
email: {
required,
email,
},
age: {
required,
numeric,
},
},
},
}
FAQs
Croud form building blocks
We found that croud-forms 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
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.