Skip to content

Commit

Permalink
pkp/pkp-lib#8850 Add disabled property for form text in ui-library
Browse files Browse the repository at this point in the history
  • Loading branch information
ipula committed Mar 28, 2023
1 parent aef7a2f commit 28f965f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/components/Form/fields/FieldBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default {
formId: String,
isMultilingual: Boolean,
isRequired: Boolean,
disabled: Boolean,
showWhen: [String, Array],
primaryLocale: String,
localeKey: String,
Expand Down
20 changes: 9 additions & 11 deletions src/components/Form/fields/FieldText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@
:name="localizedName"
:aria-describedby="describedByIds"
:aria-invalid="errors && errors.length"
:disabled="isDisabled"
:disabled="disabled"
:required="isRequired"
:style="inputStyles"
/>
<span
v-if="prefix"
class="pkpFormField__inputPrefix"
v-html="prefix"
ref="prefix"
:style="prefixStyles"
@click="setFocus"
Expand All @@ -65,9 +64,9 @@
:total="locales.length"
/>
<pkp-button
v-if="optIntoEdit && isDisabled"
v-if="optIntoEdit && disabled"
class="pkpFormField--text__optIntoEdit"
@click="isDisabled = false"
@click="enable()"
>
{{ optIntoEditLabel }}
</pkp-button>
Expand All @@ -80,7 +79,6 @@
</div>
</div>
</template>

<script>
import FieldBase from './FieldBase.vue';
Expand All @@ -102,7 +100,6 @@ export default {
data() {
return {
inputStyles: {},
isDisabled: false,
prefixStyles: {},
};
},
Expand Down Expand Up @@ -143,6 +140,12 @@ export default {
setFocus() {
this.$refs.input.focus();
},
/**
* Set disable prop false
*/
enable() {
this.$emit('change', this.disabled, 'disabled', false);
},
},
mounted() {
/**
Expand Down Expand Up @@ -194,11 +197,6 @@ export default {
}
}, 700);
});
// Set the field to disabled if optIntoEdit is passed
if (this.optIntoEdit) {
this.isDisabled = true;
}
},
};
</script>
Expand Down
1 change: 1 addition & 0 deletions src/docs/components/Form/fields/FieldBase/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
| `groupId` | The ID of the group this field should appear in. |
| `formId` | The ID of the form this field should appear in. This is passed down from the `Form`. |
| `isRequired` | Whether or not a value for this field should be required. |
| `disabled` | Used in the `disabled` attribute of `<input>`, `<textarea>`, `<select>` and other fields. |
| `isMultilingual` | Whether or not this field should be presented for each supported language. |
| `localeKey` | If the field `isMultilingual`, this will be set to the locale key of this particular instance. This is passed down from the `Form`. |
| `primaryLocale` | The primary locale for this form. This is passed down from the `Form`. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import PreviewFieldTextPrefix from './previews/PreviewFieldTextPrefix.vue';
import PreviewFieldTextPrefixTemplate from '!raw-loader!./previews/PreviewFieldTextPrefix.vue';
import PreviewFieldTextOptIntoEdit from './previews/PreviewFieldTextOptIntoEdit.vue';
import PreviewFieldTextOptIntoEditTemplate from '!raw-loader!./previews/PreviewFieldTextOptIntoEdit.vue';
import PreviewFieldTextDisable from './previews/PreviewFieldTextDisable.vue';
import PreviewFieldTextDisableTemplate from '!raw-loader!./previews/PreviewFieldTextDisable.vue';
import readme from '!raw-loader!./readme.md';
export default {
Expand Down Expand Up @@ -45,6 +47,11 @@ export default {
name: 'Editing Opt-in',
template: this.extractTemplate(PreviewFieldTextOptIntoEditTemplate),
},
{
component: PreviewFieldTextDisable,
name: 'Disable',
template: this.extractTemplate(PreviewFieldTextDisableTemplate),
},
],
};
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<field-text v-bind="field" @change="change" label="Disable" />
</template>

<script>
import FieldText from '@/components/Form/fields/FieldText.vue';
import PreviewFieldBase from '../../FieldBase/previews/PreviewFieldBase.vue';
import fieldBase from '../../../helpers/field-base';
import field from '../../../helpers/field-text-given-name';
export default {
extends: PreviewFieldBase,
components: {
FieldText,
},
data() {
return {
field: {
...fieldBase,
...field,
isRequired: false,
disabled: true,
},
};
},
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,18 @@ export default {
...fieldBase,
...field,
isRequired: false,
disabled: true,
},
};
},
methods: {
change(name, prop, newValue, localeKey) {
if (localeKey) {
this.field[prop][localeKey] = newValue;
} else {
this.field[prop] = newValue;
}
},
},
};
</script>
1 change: 1 addition & 0 deletions src/docs/components/Form/helpers/field-text-given-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export default {
inputType: 'text',
label: 'Given Name',
isRequired: true,
disabled: false,
value: '',
};

0 comments on commit 28f965f

Please sign in to comment.