[英]why this validation doesnt work??? with jade angularjs jquery and twitter bootstrap
i make a form and i want to validate before jump to the next step this is an important example that i want to try to do. 我做了一个表格,我想在跳到下一步之前进行验证,这是我想要尝试的一个重要示例。 In this example if the email is not valid the step dont work 在此示例中,如果电子邮件无效,则该步骤无效
so i try to put this on my form but is not working 所以我尝试把它放在我的表格上,但是不起作用
this is the jade file 这是玉档案
link(rel='stylesheet',href='/stylesheets/index/publicacion/alquiler/departamento.css')
script(type='text/javascript',src='/javascripts/assets/angular.min.js')
#alquiler_departamento.row-fluid(ng-controller="RegisterCtrl")
form(name='myForm',id="alquiler_departamento_formulario", onselectstart="return false", ondragstart="return false",action='/publicar',method='post',enctype="multipart/form-data")
input(type='hidden',name='tipo-operacion',value='Alquiler' ,tipo-operacion)
input(type='hidden',name='categoria',value='Departamento' ,categoria)
ul.nav.nav-tabs
li(ng-repeat='step in steps', ng-class='{active: $index==getCurrentStepIndex()}')
a(href='javascript:void(0)', ng-click='goToStep($index)') {{step}}
#seleccion(ng-switch on="selection")
#paso_uno(ng-switch-when="Step 1: Team Info")
#datos_titulo.span8
legend Titulo de la Publicacion
.control-group
.controls
input.input-block-level(type='text',placeholder="Ingrese un titulo para la publicacion",id='titulo_publicacion',name='titulo_publicacion',class='caja_texto')
.alert.alert-info
tt *- Coloque el titulo de la publicacion que aparecera en la cabecera de la misma.
#datos_ubicacion.span8
input(type='hidden',id='latitud',name='lat')
input(type='hidden',id='longitud',name='lng')
legend Ubicacion
#datos_ubicacion_selects.span12
.control-group.play-blok
label.control-label(for='select_provincias') Provincia
.controls
select(id='select_provincias',name='cod_provincia')
option(value='') -Seleccione Provincia-
option(value="5") Cordoba
.control-group.play-blok
label.control-label(for='select_ciudades') Localidad
.controls
select(id='select_ciudades',name='cod_localidad')
option(value='') -Seleccione Localidad-
option(value='0') -Otra Localidad-
.control-group.play-blok
label.control-label(for='select_barrios') Barrio
.controls
select(id='select_barrios',name='cod_barrio')
option(value='') -Seleccione Barrio-
option(value='0') -Otro Barrio-
#datos_ubicacion_mapa.span12
include ../../../partials/gmaps/gmaps_publicacion
#datos_ubicacion_direccion.span12
.control-group.play-blok
label.control-label(for='direccion') Calle
.controls
input(type='text',placeholder="Calle o Direccion exacta",class='direccion',id='direccion',name='calle')
.control-group.play-blok
label.control-label(for='numero') Altura
.controls
input(type='text',placeholder="Altura de Calle",class='numero',id='numero',name='numero')
#datos_verticales.span4
legend Departamento
.control-group.play-blok
label.control-label(for='piso') Piso
.controls
input.input-small(type='text',name='piso',class='piso',id='piso',placeholder='1-99 o A-Z')
.control-group.play-blok
label.control-label(for='departamento') Departamento
.controls
input.input-small(type='text',name='departamento',class='departamento',id='departamento',placeholder='1-99 o A-Z')
.control-group.margen-ten
label.control-label(for='disponibilidad') Disponibilidad
.controls
select.input-medium(name='disponibilidad',id='disponibilidad')
option(value="Inmediata") Inmediata
option(value='') A partir de
input(id="fecha",name='fecha',type="date")
#paso_dos(ng-switch-when="Step 2: Campaign Info")
h2 hola paso dos
#paso_tres(ng-switch-when="Step 3: Campaign Media")
h2 hola paso tres
.clearfix
ul.pager.pull-left
li(ng-class='{disabled: !hasPreviousStep()}')
a(href='javascript:void(0);', ng-click='decrementStep()') ← Previous Step
li(ng-class='{disabled: myForm.$invalid}')
a(href='javascript:void(0);', ng-click='incrementStep(myForm)') Next Step →
.pull-right
button.btn.btn-success(style='margin: 20px 0;') Confirm and Register
.clearfix
script(type='text/javascript',src='/javascripts/index/publicacion/alquiler/alquiler_departamento_angular_config.js')
script(type='text/javascript',src='javascripts/index/publicacion/alquiler/publicar_alquiler_select_funciones.js')
and this is the js including the angular configuration 这是包括角度配置的js
// Declare app level module which depends on filters, and services
var app = angular.module('myApp', []);
app.directive('tituloPublicacion', function() {
return {
require: 'ngModel',
restrict: 'A',
link: function(scope, elm, attrs, ctrl) {
ctrl.$parsers.unshift(function(viewValue) {
if(viewValue && viewValue.match(/[a-z0-9\-_]+@[a-z0-9\-_]+\.[a-z0-9\-_]{2,}/)) {
// it is valid
ctrl.$setValidity('titulo_publicacion', true);
return viewValue;
} else {
// it is invalid, return undefined (no model update)
ctrl.$setValidity('titulo_publicacion', false);
return undefined;
}
});
}
};
});
function RegisterCtrl($scope, $location) {
$scope.steps = [
'Step 1: Team Info',
'Step 2: Campaign Info',
'Step 3: Campaign Media'
];
$scope.selection = $scope.steps[0];
$scope.getCurrentStepIndex = function(){
// Get the index of the current step given selection
return _.indexOf($scope.steps, $scope.selection);
};
// Go to a defined step index
$scope.goToStep = function(index) {
if ( !_.isUndefined($scope.steps[index]) )
{
$scope.selection = $scope.steps[index];
}
};
$scope.hasNextStep = function(){
var stepIndex = $scope.getCurrentStepIndex();
var nextStep = stepIndex + 1;
// Return true if there is a next step, false if not
return !_.isUndefined($scope.steps[nextStep]);
};
$scope.hasPreviousStep = function(){
var stepIndex = $scope.getCurrentStepIndex();
var previousStep = stepIndex - 1;
// Return true if there is a next step, false if not
return !_.isUndefined($scope.steps[previousStep]);
};
$scope.incrementStep = function(form) {
if (form.$invalid) return;
if ( $scope.hasNextStep() )
{
var stepIndex = $scope.getCurrentStepIndex();
var nextStep = stepIndex + 1;
$scope.selection = $scope.steps[nextStep];
}
};
$scope.decrementStep = function() {
if ( $scope.hasPreviousStep() )
{
var stepIndex = $scope.getCurrentStepIndex();
var previousStep = stepIndex - 1;
$scope.selection = $scope.steps[previousStep];
}
};
}
why is not working the titulo_publicacion validate??? 为什么不起作用titulo_publicacion验证??? tnx! tnx!
EDIT 2 编辑2
this is the result of the form image the tabs dont work 这是选项卡不起作用的表单图像的结果
Register your directive as tituloPublicacion
, not titulo_publicacion
. 将您的指令注册为tituloPublicacion
, 而不是 titulo_publicacion
。 In your html/jade, use titulo-publicacion
. 在您的html / jade中,使用titulo-publicacion
。
You need to add it to your input field too: 您还需要将其添加到输入字段中:
input(type='hidden',name='tipo_operacion',value='Alquiler', tipo-operacion)
In your directive use restrict: 'A'
. 在您的指令中使用restrict: 'A'
。
I didn't see it in your snippet, but you need to let angular bootstrap itself: 我没有在您的代码段中看到它,但是您需要让角度引导程序本身:
html(ng-app='myApp')
You are not injecting services correctly . 您没有正确注入服务 。 Try to use the non-minified angular version for now. 暂时尝试使用非最小化的角度版本。
You have to create controllers like: 您必须创建类似的控制器:
app.controller('RegisterCtrl', ['$scope', 'location', function($scope, $location) {
$scope.steps = [
'Step 1: Team Info',
'Step 2: Campaign Info',
'Step 3: Campaign Media'
];
...
}]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.