I’ve been tring to create a field using component in plugin configuration, and I’ve successfully created a field using a component in config.xml . I’ve managed to save the field data to the database, but I’m facing an issue—I can’t seem to make the field required. Any ideas on how we can make a field created using a component required?
custompluginsTestModulesrcResourcesappadministrationsrccomponentfield-bindfield-ibanfield-iban-text.html.twig
<template>
<sw-text-field
:disabled="shouldDisable"
name="TestModule.config.iban"
:value="currentValue"
@change="onChange"
@input="onInput"
:required="isRequired"
label="IBAN/QR-IBAN Number for Classic format"
/>
</template>
custompluginsTestModulesrcResourcesappadministrationsrccomponentfield-bindfield-ibanindex.js
const {Component} = Shopware;
import template from './field-iban-text.html.twig'
Component.register('field-iban-text',
{
template,
props: {
value: {
type: String,
required: true,
default: '',
},
},
methods: {
disableField() {
return this.$attrs.myConfig.elements.find(element => element.config?.specialType === 'disable')['name']
},
onChange(event) {
this.$emit('change', value || '');
},
onInput(value) {
this.$emit('input', value);
},
},
computed: {
shouldDisable() {
if(this.$attrs.actualConfigData[this.disableField()] === 'SCOR'){
return true;
}else {
return false;
}
},
isRequired(){
if(this.$attrs.actualConfigData[this.disableField()] === 'QRR'){
return true;
}else {
return false;
}
}
},
data() {
return {
currentValue: this.value,
};
},
watch: {
value(value) {
this.currentValue = value;
},
},
});
Syam S Gopal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.