Commit c976e8d3 authored by Justin Ho's avatar Justin Ho

Refactor component code

parent c6c23f3c
...@@ -73,19 +73,18 @@ export default { ...@@ -73,19 +73,18 @@ export default {
return this.isPassword && !isEmpty(this.value); return this.isPassword && !isEmpty(this.value);
}, },
label() { label() {
const title = this.title || startCase(this.name);
if (this.isNonEmptyPassword) { if (this.isNonEmptyPassword) {
return sprintf(__('Enter new %{field_title}'), { return sprintf(__('Enter new %{field_title}'), {
field_title: this.computedTitle, password: title,
}); });
} }
return this.computedTitle; return title;
}, },
passwordRequired() { passwordRequired() {
return isEmpty(this.value) && this.required; return isEmpty(this.value) && this.required;
}, },
computedTitle() {
return this.title || startCase(this.name);
},
options() { options() {
return this.choices.map(choice => { return this.choices.map(choice => {
return { return {
...@@ -100,6 +99,12 @@ export default { ...@@ -100,6 +99,12 @@ export default {
fieldName() { fieldName() {
return `service[${this.name}]`; return `service[${this.name}]`;
}, },
sharedProps() {
return {
id: this.fieldId,
name: this.fieldName,
};
},
}, },
created() { created() {
if (this.isNonEmptyPassword) { if (this.isNonEmptyPassword) {
...@@ -113,29 +118,20 @@ export default { ...@@ -113,29 +118,20 @@ export default {
<gl-form-group :label="label" :label-for="fieldId" :description="help"> <gl-form-group :label="label" :label-for="fieldId" :description="help">
<template v-if="isCheckbox"> <template v-if="isCheckbox">
<input :name="fieldName" type="hidden" value="false" /> <input :name="fieldName" type="hidden" value="false" />
<gl-form-checkbox :id="fieldId" v-model="model" :name="fieldName" /> <gl-form-checkbox v-model="model" v-bind="sharedProps" />
</template> </template>
<gl-form-select v-else-if="isSelect" v-model="model" v-bind="sharedProps" :options="options" />
<gl-form-select
v-else-if="isSelect"
:id="fieldId"
v-model="model"
:name="fieldName"
:options="options"
/>
<gl-form-textarea <gl-form-textarea
v-else-if="isTextarea" v-else-if="isTextarea"
:id="fieldId"
v-model="model" v-model="model"
:name="fieldName" v-bind="sharedProps"
:placeholder="placeholder" :placeholder="placeholder"
:required="required" :required="required"
/> />
<gl-form-input <gl-form-input
v-else-if="isPassword" v-else-if="isPassword"
:id="fieldId"
v-model="model" v-model="model"
:name="fieldName" v-bind="sharedProps"
:type="type" :type="type"
autocomplete="new-password" autocomplete="new-password"
:placeholder="placeholder" :placeholder="placeholder"
...@@ -143,9 +139,8 @@ export default { ...@@ -143,9 +139,8 @@ export default {
/> />
<gl-form-input <gl-form-input
v-else v-else
:id="fieldId"
v-model="model" v-model="model"
:name="fieldName" v-bind="sharedProps"
:type="type" :type="type"
:placeholder="placeholder" :placeholder="placeholder"
:required="required" :required="required"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment