mikeerickson/validatorjs

:attribute showing field name instead of field label

Open

#232 opened on 2018年1月15日

GitHub で見る
 (2 comments) (0 reactions) (1 assignee)JavaScript (1,658 stars) (279 forks)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

コントリビューターガイド

:attribute showing field name instead of field label · mikeerickson/validatorjs#232 | Good First Issue