validatorjs icon indicating copy to clipboard operation
validatorjs copied to clipboard

:attribute showing field name instead of field label

Open codebury opened this issue 8 years ago • 2 comments

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

codebury avatar Jan 15 '18 23:01 codebury

I am having a similar issue when using the required_unless_all rule.

Is Pull Request #225 related to this issue?

mattscooter avatar Feb 07 '18 00:02 mattscooter

@mattscooter as you can see @codebury mentioned that the version used was 3.14.2

While according to @skaterdav85 it has been released in 3.13.6

muhammadyibr avatar Feb 23 '18 09:02 muhammadyibr