Adds option to define maxlenght on simple text metadata.
This commit is contained in:
parent
1d9dc775db
commit
f8c622ea36
|
@ -1,5 +1,19 @@
|
||||||
<template>
|
<template>
|
||||||
<section>
|
<section>
|
||||||
|
<b-field :addons="false">
|
||||||
|
<label class="label is-inline">
|
||||||
|
{{ $i18n.getHelperTitle('tainacan-text', 'maxlength') }}
|
||||||
|
<help-button
|
||||||
|
:title="$i18n.getHelperTitle('tainacan-text', 'maxlength')"
|
||||||
|
:message="$i18n.getHelperMessage('tainacan-text', 'maxlength')" />
|
||||||
|
</label>
|
||||||
|
<b-numberinput
|
||||||
|
v-model="maxlength"
|
||||||
|
name="maxlength"
|
||||||
|
step="1"
|
||||||
|
min="0"
|
||||||
|
@update:model-value="onUpdateMaxlength" />
|
||||||
|
</b-field>
|
||||||
<b-field
|
<b-field
|
||||||
:addons="false"
|
:addons="false"
|
||||||
:label="$i18n.getHelperTitle('tainacan-text', 'display_suggestions')">
|
:label="$i18n.getHelperTitle('tainacan-text', 'display_suggestions')">
|
||||||
|
@ -39,21 +53,28 @@
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
displaySuggestions: String,
|
displaySuggestions: String,
|
||||||
mask: String
|
mask: String,
|
||||||
|
maxlength: [Number, null]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.displaySuggestions = this.value && this.value.display_suggestions ? this.value.display_suggestions : 'no';
|
this.displaySuggestions = this.value && this.value.display_suggestions ? this.value.display_suggestions : 'no';
|
||||||
this.mask = this.value && this.value.mask ? this.value.mask : '';
|
this.mask = this.value && this.value.mask ? this.value.mask : '';
|
||||||
|
this.maxlength = this.value && this.value.maxlength ? Number(this.value.maxlength) : null;
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onUpdateDisplaySuggestions(value) {
|
onUpdateDisplaySuggestions(value) {
|
||||||
this.displaySuggestions = value;
|
this.displaySuggestions = value;
|
||||||
this.$emit('update:value', { display_suggestions: value, mask: value == 'yes' ? '' : this.mask });
|
this.$emit('update:value', { display_suggestions: value, mask: value == 'yes' ? '' : this.mask, maxlength: this.maxlength });
|
||||||
},
|
},
|
||||||
onUpdateMask(value) {
|
onUpdateMask(value) {
|
||||||
this.mask = value;
|
this.mask = value;
|
||||||
this.$emit('update:value', { display_suggestions: this.displaySuggestions, mask: value });
|
this.$emit('update:value', { display_suggestions: this.displaySuggestions, mask: value, maxlength: this.maxlength });
|
||||||
|
},
|
||||||
|
onUpdateMaxlength(value) {
|
||||||
|
if (value == 0) value = null;
|
||||||
|
|
||||||
|
this.$emit('update:value', { maxlength: value, display_suggestions: this.displaySuggestions, mask: this.mask });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,10 +10,17 @@
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
:value="value"
|
:value="value"
|
||||||
:placeholder="itemMetadatum.metadatum.placeholder ? itemMetadatum.metadatum.placeholder : ''"
|
:placeholder="itemMetadatum.metadatum.placeholder ? itemMetadatum.metadatum.placeholder : ''"
|
||||||
|
:maxlength="getMaxlength"
|
||||||
@focus="onMobileSpecialFocus"
|
@focus="onMobileSpecialFocus"
|
||||||
@complete="($event) => getMask ? onInput($event.detail.value) : null"
|
@complete="($event) => getMask ? onInput($event.detail.value) : null"
|
||||||
@input="($event) => getMask ? null : onInput($event.target.value)"
|
@input="($event) => getMask ? null : onInput($event.target.value)"
|
||||||
@blur="onBlur">
|
@blur="onBlur">
|
||||||
|
<small
|
||||||
|
v-if="getMaxlength"
|
||||||
|
class="help counter"
|
||||||
|
:class="{ 'is-invisible': !isInputFocused }" >
|
||||||
|
{{ value.length }} / {{ getMaxlength }}
|
||||||
|
</small>
|
||||||
</div>
|
</div>
|
||||||
<b-autocomplete
|
<b-autocomplete
|
||||||
v-else
|
v-else
|
||||||
|
@ -26,6 +33,7 @@
|
||||||
clearable
|
clearable
|
||||||
:placeholder="itemMetadatum.metadatum.placeholder ? itemMetadatum.metadatum.placeholder : ''"
|
:placeholder="itemMetadatum.metadatum.placeholder ? itemMetadatum.metadatum.placeholder : ''"
|
||||||
check-infinite-scroll
|
check-infinite-scroll
|
||||||
|
:maxlength="getMaxlength"
|
||||||
@blur="onBlur"
|
@blur="onBlur"
|
||||||
@update:model-value="($event) => { search($event); }"
|
@update:model-value="($event) => { search($event); }"
|
||||||
@select="onSelect"
|
@select="onSelect"
|
||||||
|
@ -81,7 +89,8 @@
|
||||||
totalFacets: 0,
|
totalFacets: 0,
|
||||||
query: '',
|
query: '',
|
||||||
currentCollectionId: '',
|
currentCollectionId: '',
|
||||||
filter: undefined
|
filter: undefined,
|
||||||
|
isInputFocused: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -99,6 +108,12 @@
|
||||||
};
|
};
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
},
|
||||||
|
getMaxlength() {
|
||||||
|
if ( this.itemMetadatum && this.itemMetadatum.metadatum.metadata_type_options && this.itemMetadatum.metadatum.metadata_type_options.maxlength !== null && this.itemMetadatum.metadatum.metadata_type_options.maxlength !== undefined && this.itemMetadatum.metadatum.metadata_type_options.maxlength !== '' )
|
||||||
|
return Number(this.itemMetadatum.metadatum.metadata_type_options.maxlength);
|
||||||
|
else
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
@ -108,9 +123,14 @@
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onInput(value) {
|
onInput(value) {
|
||||||
|
const inputRef = this.$refs['tainacan-item-metadatum_id-' + this.itemMetadatum.metadatum.id + (this.itemMetadatum.parent_meta_id ? ('_parent_meta_id-' + this.itemMetadatum.parent_meta_id) : '')];
|
||||||
|
if ( inputRef && this.getMaxlength && !inputRef.checkHtml5Validity() )
|
||||||
|
return;
|
||||||
|
|
||||||
this.$emit('update:value', value);
|
this.$emit('update:value', value);
|
||||||
},
|
},
|
||||||
onBlur() {
|
onBlur() {
|
||||||
|
this.isInputFocused = false;
|
||||||
this.$emit('blur');
|
this.$emit('blur');
|
||||||
},
|
},
|
||||||
onSelect(option){
|
onSelect(option){
|
||||||
|
@ -190,6 +210,7 @@
|
||||||
this.search(this.searchQuery);
|
this.search(this.searchQuery);
|
||||||
}, 250),
|
}, 250),
|
||||||
onMobileSpecialFocus() {
|
onMobileSpecialFocus() {
|
||||||
|
this.isInputFocused = true;
|
||||||
this.$emit('mobile-special-focus');
|
this.$emit('mobile-special-focus');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,10 @@ class Text extends Metadata_Type {
|
||||||
__( 'Define a pattern of fixed characters that will be used to mask the input. Learn how to build mask patterns <a target="_blank" href="%1$s">here</a>.', 'tainacan' ),
|
__( 'Define a pattern of fixed characters that will be used to mask the input. Learn how to build mask patterns <a target="_blank" href="%1$s">here</a>.', 'tainacan' ),
|
||||||
'https://imask.js.org/guide.html#masked-pattern'
|
'https://imask.js.org/guide.html#masked-pattern'
|
||||||
)
|
)
|
||||||
|
],
|
||||||
|
'maxlength' => [
|
||||||
|
'title' => __( 'Maximum of characters', 'tainacan' ),
|
||||||
|
'description' => __( 'Limits the character input to a maximum value an displays a counter.', 'tainacan' ),
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
&.has-icons-left {
|
&.has-icons-left {
|
||||||
.icon {
|
.icon {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
|
&:has(+.help) { // Maxlenght count in autocomplete needs this
|
||||||
|
height: 32px;
|
||||||
|
}
|
||||||
.mdi::before {
|
.mdi::before {
|
||||||
color: var(--tainacan-info-color);
|
color: var(--tainacan-info-color);
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
Loading…
Reference in New Issue