Skip to content

Commit

Permalink
add submit listener to rpl-form, flagged emitter on optionbutton, dem…
Browse files Browse the repository at this point in the history
…o story (#1184)
  • Loading branch information
waitingallday committed Apr 14, 2022
1 parent 7969239 commit 3eedd15
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
66 changes: 66 additions & 0 deletions packages/components/Molecules/Form/Form.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,69 @@ export const formData = {
</Story>
</Canvas>

export const optBtnFormData = {
model: {
text: null,
title_az: ''
},
schema: {
fields: [
{
type: 'input',
inputType: 'text',
label: 'Search',
hint: '',
placeholder: 'Keyword',
model: 'text'
},
{
type: 'rploptionbutton',
label: 'Option button default',
model: 'title_az',
submitOnClick: true
}
],
groups: [
{
fields: [
{
type: 'rplsubmitloader',
buttonText: 'Submit (with animation)',
loading: false,
autoUpdate: true,
styleClasses: ['form-group--inline']
},
{
type: 'rplclearform',
buttonText: 'Clear search filters',
styleClasses: ['form-group--inline']
}
]
}
]
},
tag: 'rpl-fieldset',
formOptions: {
validateAfterLoad: false,
validateAfterChanged: false
},
formState: {}
};

<Canvas>
<Story
name="Option button, submit on click"
args={{
formData: optBtnFormData,
title: 'Option button, submit on click',
fullWidth: false,
isNewModel: true,
options: {
validateAfterChanged: false,
validateAfterLoad: false
}
}}
>
{TemplateForm.bind({})}
</Story>
</Canvas>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<script>
import { abstractField } from 'vue-form-generator'
import { RplFormEventBus } from '@dpc-sdp/ripple-form'
export default {
name: 'RplOptionButton',
Expand All @@ -29,6 +30,9 @@ export default {
},
onSelection (item) {
this.value = item
if (this.schema.submitOnClick) {
RplFormEventBus.$emit('submitform')
}
},
isItemChecked (item) {
return (item === this.value)
Expand Down
2 changes: 2 additions & 0 deletions packages/components/Molecules/Form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export default {
RplFormEventBus.$on('clearform', this.clearForm)
}
RplFormEventBus.$on('submitform', this.onSubmit)
// TODO: We should abstract all future custom validators to a separate file and import them here.
VueFormGenerator.validators.rplWordCount = function (value, field) {
let wordCount = value ? value.trim().split(/\s+/).length : 0
Expand Down

0 comments on commit 3eedd15

Please sign in to comment.