Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
ExtJS - Optional model field with validation

In ExtJS 6.02 is it possible to have a field model that is optional but also has validation?

Example an email field that may or not be present but the email must be valid if it exists.

Ext.define('my_model', {
   extend  : 'Ext.data.Model',

   identifier: {
      type      : 'sequential',
      seed      : 1,
      increment : 1
   },

   fields: [{
      name : 'date',
      type : 'date'
   }, {
      name : 'msg',
      type : 'string',
   }, {
      name : 'email',
      type : 'string',
   }],

   validators: {
      date: {
         type: 'presence'
      },
      msg: {
         type : 'length',
         min  : 2
      },
      email: {
         type : 'email'
      }
   }
});

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can override matcher of email validator to allow empty string:

Ext.define('my_model', {
    extend: 'Ext.data.Model',

    identifier: {
        type: 'sequential',
        seed: 1,
        increment: 1
    },

    fields: [{
        name: 'date',
        type: 'date'
    }, {
        name: 'msg',
        type: 'string',
    }, {
        name: 'email',
        type: 'string',
        allowBlank: true
    }],

    validators: {
        date: {
            type: 'presence'
        },
        msg: {
            type: 'length',
            min: 2
        },
        email: {
            type: 'email',
            // Override matcher to allow empty string
            matcher: /^$|^(")?(?:[^\."])(?:(?:[\.])?(?:[\w\-!#$%&'*+\/=?\^_`{|}~]))*\1@(\w[\-\w]*\.){1,5}([A-Za-z]){2,6}$/
        }
    }
});

Ext.application({
    name: 'Fiddle',

    launch: function () {
        var myModel = Ext.create('my_model', {
            date: new Date(),
            msg: 'Some Message',
            //email: 'mustermann@gmail.com',
            email: '',
        });
        console.log(myModel.isValid());
    }
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda