Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#8850 Add disabled property for form text in ui-library #269

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these two lines removed for a reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this also merging issue

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: '',
};