Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #32 from alvarosaburido/feature/form_field_id_conf…
Browse files Browse the repository at this point in the history
…igurable

Configurable id, default with form id to avoid duplicated ids
  • Loading branch information
alvarosabu authored Jun 3, 2020
2 parents 90dc4b7 + 9b332c7 commit 0730769
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions dev/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const data = () => ({
customClass: 'col-12',
}),
new FormField({
id: 'number-custom-id',
type: 'number',
label: 'Number',
name: 'number',
Expand Down
4 changes: 4 additions & 0 deletions docs/guide/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This is the principal instance containing the info of your field, as seen in sev

```javascript
export function FormField({
id,
type = 'text',
value = null,
validations = [],
Expand All @@ -17,6 +18,7 @@ export function FormField({
placeholder = null,
inline = false,
}) {
this.id = id;
this.type = type;
this.value = value;
this.validations = validations;
Expand All @@ -36,6 +38,7 @@ Tracks the value and validation status of an individual form control. `FormContr

```javascript
export function FormControl({
id,
type = null,
value = null,
validations = [],
Expand All @@ -49,6 +52,7 @@ export function FormControl({
touched = false,
dirty = false,
}) {
this.id = id || `${form}-${name}`;
this.type = type;
this.value = value;
this.validations = validations;
Expand Down
3 changes: 3 additions & 0 deletions src/components/dynamic-form/DynamicForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const methods = {
field =>
new FormControl({
...field,
form: this.id,
}),
);
},
Expand All @@ -42,6 +43,7 @@ const methods = {
field =>
new FormControl({
...field,
form: this.id,
}),
);
},
Expand All @@ -63,6 +65,7 @@ const methods = {
field =>
new FormControl({
...field,
form: this.id,
valid: true,
value: null,
touched: false,
Expand Down
2 changes: 1 addition & 1 deletion src/components/input-select/InputSelect.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<select
:id="formControl.name"
:id="formControl.id"
v-model="formControl.value"
:name="formControl.name"
class="form-control"
Expand Down
2 changes: 1 addition & 1 deletion src/components/input-text/InputText.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<input
:id="formControl.name"
:id="formControl.id"
v-model="formControl.value"
:name="formControl.name"
class="form-control"
Expand Down
2 changes: 1 addition & 1 deletion src/components/input-textarea/InputTextarea.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<textarea
:id="formControl.name"
:id="formControl.id"
v-model="formControl.value"
:name="formControl.name"
class="form-control"
Expand Down
6 changes: 6 additions & 0 deletions src/core/utils/form-control.model.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export function FormControl({
id,
type = null,
value = null,
validations = [],
label = null,
form,
name = null,
customClass = null,
options = [],
Expand All @@ -14,7 +16,9 @@ export function FormControl({
touched = false,
dirty = false,
}) {
this.id = id || `${form}-${name}`;
this.type = type;
this.form = form;
this.value = value;
this.validations = validations;
this.label = label;
Expand All @@ -31,6 +35,7 @@ export function FormControl({
}

export function FormField({
id,
type = 'text',
value = null,
validations = [],
Expand All @@ -44,6 +49,7 @@ export function FormField({
rows = null,
cols = null,
}) {
this.id = id;
this.type = type;
this.value = value;
this.validations = validations;
Expand Down

0 comments on commit 0730769

Please sign in to comment.