Validacion url&email
Hola que tal a todos! tengo un pequeño problema al tratar de validar la informacion(url,email) contenida en una caja de texto, dependiente de un combo de seleccion este es mi codigo:
var array =[['1','MAIL'],['2','URL']];
var store = new Ext.data.ArrayStore({
fields: [
{name: 'clave'},
{name: 'descr'}
]
});
store.loadData(array);
var combo = new Ext.form.ComboBox({
store:store,
fieldLabel :'Validacion',
displayField:'state',
typeAhead: true,
mode: 'local',
width:200,
forceSelection: true,
readOnly :true,
triggerAction: 'all',
emptyText:'Select Valid...',
valueField: 'clave',
displayField: 'descr',
selectOnFocus:true
});
var txt = new Ext.form.TextField({
id:'txt',
width:200,
fieldLabel :'Valor',
allowBlank:false,
maxLength:100
});
var win = new Ext.Window({
title:'Hola ExtJS',
width:350,
height:300,
layout:'form',
minimizable:true,
maximizable:true,
items:[combo,txt]
});
combo.on('select',function(combo,record,index ){
if(record.get('clave') == '1'){
txt.vtype='email';
}
else{
txt.vtype='url';
}
},this);
win.show();
El problema es que no puedo cambiar la propiedad vtype al seleccionar un item del combo, espero alguien pueda ayudarme.
saludos..Hola Lestat, he probado tu code y si cambia la propiedad vtype, seguro te refieres a que si por ejemplo tienes un texto en la caja: "hola" y seleccionas el valor URL del combo, debería marcarte como error. Si es así deberías añadirle:
txt.validate();despues de cada cambio de vtype. esto es para que vuelva a validar y actualice el mensaje de error. saludos.
Hola Gracias mayerhorna por la solucion!!
asi quedo mi codigo:
Ext.namespace('CursoExtJS');
CursoExtJS.CrearVentana = {
init: function(){
var array =[['1','MAIL'],['2','URL']];
var store = new Ext.data.ArrayStore({
fields: [
{name: 'clave'},
{name: 'descr'}
]
});
store.loadData(array);
var combo = new Ext.form.ComboBox({
store:store,
fieldLabel :'Validacion',
displayField:'state',
typeAhead: true,
mode: 'local',
width:200,
forceSelection: true,
readOnly :true,
triggerAction: 'all',
emptyText:'Select Valid...',
valueField: 'clave',
displayField: 'descr',
selectOnFocus:true
});
var txt = new Ext.form.TextField({
id:'txt',
width:200,
fieldLabel :'Valor',
allowBlank:false,
maxLength:100
});
var win = new Ext.Window({
title:'Hola ExtJS',
width:350,
height:300,
layout:'form',
minimizable:true,
maximizable:true,
items:[combo,txt]
});
combo.on('select',function(combo,record,index ){
if(record.get('clave') == '1'){
txt.vtype='email';
txt.validate();
}
else{
txt.vtype='url';
txt.validate();
}
},this);
win.show();
}
}
//Cuando el DOM esté listo se invoca la función “init”
Ext.onReady(CursoExtJS.CrearVentana.init,CursoExtJS.CrearVentana);
dependiendo del combo seleccionado realiza la validacion <!-- s:D --><!-- s:D -->¿Conoces a alguien que pueda responder esta pregunta? Comparte el link en Twitter o Facebook
Es necesario registrarse para poder participar en el foro! Si ya tienes una cuenta puedes entrar y comentar en este foro.
