mikeerickson/validatorjs
View on GitHub:attribute showing field name instead of field label
Open
#232 opened on Jan 15, 2018
bughelp wantednext
Description
Hi,
const editLocationFields = {
fields: [
'Calle',
'NumExt',
'NumInt',
'Colonia',
'Indicaciones',
'Tipo',
'lat',
'lng'
],
labels: {
Tipo: 'Tipo de ubicación',
NumExt: 'Número Exterior',
NumInt: 'Número Interior',
Indicaciones: 'Indicaciones'
},
rules: {
Calle: 'required|string',
NumExt: 'required_if:Tipo,Casa|string',
Tipo: 'required|string'
}
}
messages.js:48
_getAttributeName: function(attribute) {
var name = attribute;
if (this.attributeNames.hasOwnProperty(attribute)) {
return this.attributeNames[attribute];
} else if (this.messages.attributes.hasOwnProperty(attribute)) {
name = this.messages.attributes[attribute];
}
...
this.attributeNames only has NumExt fileld so when trying to find Tipo field, getAttributeName doesn't find anything and finally returns :attribute to key replacement (Tipo in this case). I suppose this.attributeNames must contains Tipo: "Tipo de ubicación" definition too.
Expected message: "Este campo es requerido cuando Tipo de ubicación es Casa" Current message: "Este campo es requerido cuando Tipo es Casa"
Is there something wrong with my fields definition?
Some help is much appreciated.
version: 3.14.2