Feature: Add default value to ChatForm (#816)
* Feature: Add adefault value to ChatForm
This commit is contained in:
parent
5bc8219db5
commit
44fae4a4a1
@ -21,7 +21,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
v-if="!submittedValues.length"
|
v-if="!submittedValues.length"
|
||||||
class="button small block"
|
class="button block"
|
||||||
type="submit"
|
type="submit"
|
||||||
:disabled="!isFormValid"
|
:disabled="!isFormValid"
|
||||||
>
|
>
|
||||||
@ -56,7 +56,11 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.updateFormValues();
|
if (this.submittedValues.length) {
|
||||||
|
this.updateFormValues();
|
||||||
|
} else {
|
||||||
|
this.setFormDefaults();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
@ -65,14 +69,20 @@ export default {
|
|||||||
}
|
}
|
||||||
this.$emit('submit', this.formValues);
|
this.$emit('submit', this.formValues);
|
||||||
},
|
},
|
||||||
updateFormValues() {
|
buildFormObject(formObjectArray) {
|
||||||
this.formValues = this.submittedValues.reduce((acc, obj) => {
|
return formObjectArray.reduce((acc, obj) => {
|
||||||
return {
|
return {
|
||||||
...acc,
|
...acc,
|
||||||
[obj.name]: obj.value,
|
[obj.name]: obj.value || obj.default,
|
||||||
};
|
};
|
||||||
}, {});
|
}, {});
|
||||||
},
|
},
|
||||||
|
updateFormValues() {
|
||||||
|
this.formValues = this.buildFormObject(this.submittedValues);
|
||||||
|
},
|
||||||
|
setFormDefaults() {
|
||||||
|
this.formValues = this.buildFormObject(this.items);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -82,16 +92,16 @@ export default {
|
|||||||
|
|
||||||
.form {
|
.form {
|
||||||
padding: $space-normal;
|
padding: $space-normal;
|
||||||
width: 100%;
|
width: 80%;
|
||||||
|
|
||||||
.form-block {
|
.form-block {
|
||||||
max-width: 100%;
|
width: 90%;
|
||||||
padding-bottom: $space-small;
|
padding-bottom: $space-small;
|
||||||
}
|
}
|
||||||
|
|
||||||
label {
|
label {
|
||||||
display: block;
|
display: block;
|
||||||
font-weight: $font-weight-bold;
|
font-weight: $font-weight-medium;
|
||||||
padding: $space-smaller 0;
|
padding: $space-smaller 0;
|
||||||
text-transform: capitalize;
|
text-transform: capitalize;
|
||||||
}
|
}
|
||||||
@ -103,12 +113,16 @@ export default {
|
|||||||
display: block;
|
display: block;
|
||||||
font-size: $font-size-default;
|
font-size: $font-size-default;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
padding: $space-smaller $space-small;
|
padding: $space-one;
|
||||||
width: 90%;
|
width: 100%;
|
||||||
|
|
||||||
&:disabled {
|
&:disabled {
|
||||||
background: $color-background-light;
|
background: $color-background-light;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
font-size: $font-size-default;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -2,7 +2,7 @@ class ContentAttributeValidator < ActiveModel::Validator
|
|||||||
ALLOWED_SELECT_ITEM_KEYS = [:title, :value].freeze
|
ALLOWED_SELECT_ITEM_KEYS = [:title, :value].freeze
|
||||||
ALLOWED_CARD_ITEM_KEYS = [:title, :description, :media_url, :actions].freeze
|
ALLOWED_CARD_ITEM_KEYS = [:title, :description, :media_url, :actions].freeze
|
||||||
ALLOWED_CARD_ITEM_ACTION_KEYS = [:text, :type, :payload, :uri].freeze
|
ALLOWED_CARD_ITEM_ACTION_KEYS = [:text, :type, :payload, :uri].freeze
|
||||||
ALLOWED_FORM_ITEM_KEYS = [:type, :placeholder, :label, :name, :options].freeze
|
ALLOWED_FORM_ITEM_KEYS = [:type, :placeholder, :label, :name, :options, :default].freeze
|
||||||
ALLOWED_ARTICLE_KEYS = [:title, :description, :link].freeze
|
ALLOWED_ARTICLE_KEYS = [:title, :description, :link].freeze
|
||||||
|
|
||||||
def validate(record)
|
def validate(record)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user