mikeerickson/validatorjs

:attribute showing field name instead of field label

Open

#232 建立於 2018年1月15日

在 GitHub 查看
 (2 留言) (0 反應) (1 負責人)JavaScript (1,658 star) (279 fork)batch import
bughelp wantednext

描述

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

貢獻者指南