diff --git a/src/domains/Example/Test/Prototype/TestWithHooks.js b/src/domains/Example/Test/Prototype/TestWithHooks.js index 641e573..a88294e 100644 --- a/src/domains/Example/Test/Prototype/TestWithHooks.js +++ b/src/domains/Example/Test/Prototype/TestWithHooks.js @@ -1,5 +1,6 @@ import Test from './Test' import { path } from 'src/domains/Example/Test/Routes' +import { gender } from 'src/domains/Common/options' /** * @type {TestWithHooks} @@ -21,14 +22,36 @@ export default class TestWithHooks extends Test { construct () { // construct the parent super.construct() - + // configure some fields + this.configureFields() // configure some actions this.configureActions() - // configure some hooks this.configureHooks() } + /** + */ + configureFields () { + this.field('active') + .fieldIsCheckbox({ label: 'if checked will hide "Description"' }) + .fieldFormWidth(45) + .fieldFormOrder(3, true) + .fieldOn('input', function ({ $event }) { + this.setFieldLayout('description', 'formHidden', $event) + }) + + this.field('gender') + .fieldIsRadio(gender(TestWithHooks.domain)) + .fieldFormOrder(4, true) + .fieldFormWidth(55) + .fieldOn('input', function ({ $event }) { + this.setFieldLayout('active', 'formHidden', $event === 'male') + }) + + this.field('description').fieldOn('input', this.changeDescriptionLabel) + } + /** */ configureActions () { @@ -36,7 +59,7 @@ export default class TestWithHooks extends Test { .actionColor('red') .actionTextColor('white') - this.action('go-to-test') + this.action('goToTest') .actionScopes(['index', 'create', 'read', 'update']) .actionPositions(['form-footer']) .actionIcon('send') @@ -56,13 +79,32 @@ export default class TestWithHooks extends Test { /** */ this.hook('fetch:record', function () { - this.$message.toast(this.$lang(`domains.${this.domain}.messages.record`)) + this.$message.toast(this.$lang(`domains.${this.domain}.messages.record`), { position: 'top-right' }) + if (this.record.active === undefined) { + this.setRecord('active', false) + } }) /** */ this.hook('fetch:records', function () { - this.$message.toast(this.$lang(`domains.${this.domain}.messages.records`)) + this.$message.toast(this.$lang(`domains.${this.domain}.messages.records`), { position: 'top-left' }) }) } + + /** + * @param $event + * @param field + */ + changeDescriptionLabel ({ $event, field }) { + if (!field.originalLabel) { + field.originalLabel = field.label + } + let label = $event + if (!label) { + label = field.originalLabel + field.originalLabel = undefined + } + field.label = label + } }