salix-front/src/boot/customQInput.js

78 lines
3.3 KiB
JavaScript

// src/boot/customQTh.js
import { boot } from 'quasar/wrappers';
import { QInput } from 'quasar';
import i18n from 'src/i18n';
const TR_HEADER = 'tr-header';
export default boot((b) => {
const { app } = b;
app.use(i18n);
app.mixin({
// mounted() {
// this.applyMixinLogic();
// },
mounted() {
this.applyMixinLogic();
// if (this.$options.name === QInput.name) {
// console.table([this.$options.name]);
// if (this.label) this.label = this.$t(this.label);
// // this.addClassToQTh(this);
// }
},
methods: {
applyMixinLogic() {
if (this.$options.name === 'QInput') {
// Traducción de la etiqueta
if (this.label) {
const el = this.$el;
// Recorrer los elementos hijos
const children = el.children || [];
for (let i = 0; i < children.length; i++) {
const child = children[i];
if (
child.tagName === 'DIV' &&
child.classList.contains('q-field__inner')
) {
const input = child.querySelector('input');
const filterAvailableText = (element) =>
element.__vueParentComponent.type.name === 'QInput' &&
element.__vueParentComponent?.attrs?.class !==
'vn-input-date';
if (
input &&
input.__vueParentComponent.type.name === 'QInput'
) {
// Añadir clase CSS
input.classList.add('input-default');
// Traducción de la etiqueta
const labelElement =
child.querySelector('.q-field__label');
if (labelElement) {
const labelKey = labelElement.textContent.trim();
labelElement.textContent = this.$t(labelKey);
}
}
}
}
// Traducción de la etiqueta
// const label = this.$el.getAttribute('label');
// if (label) {
// this.$el = this.$el.setAttribute('label', 'sasd');
// }
// this.$props.label = this.$t(`*${this.$props.label}`);
// this.label = this.$t(`*${this.$props.label}`);
// this.getNativeElement().ariaLabel = '++++';
}
// // Añadir clase CSS
// if (!this.$el.classList.contains('input-default')) {
// this.$el.classList.add('input-default');
// }
}
},
},
});
});