Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fn function won't update message output for if else statements msg output #350

Open
kirkdm opened this issue May 31, 2018 · 0 comments
Open

Comments

@kirkdm
Copy link

kirkdm commented May 31, 2018

Below is my code for validating a model but the fn: function doesn't update the msg output when you change the value of the form for e.g if I add text 'Admin' it will validate the first part of the value in the if statement but then it will validate the second part and the message changes but the message output won't update so it's always the first msg not the second. My other question is how do you have multiple validations for an fn call back it's like you can't. I mean I want to validate other things that have a function because I have other regular expressions to test that are different from each other. Even if I turn it into an array - multiple fn functions won't work

`define([
'jquery',
'underscore',
'backbone',
'app',
'backbone-validation',
'models/validation'
], function($, _, Backbone, App, bv, v) {

App.Models.Role = Backbone.Model.extend({
	defaults: {
		name: null,
		display_name: null,
		description: null,
	},
	validation: {
		name: {
			required: true,
			fn: 'alphadash'
		},
		display_name: {
			required: true				
		},
		description: {
			required: true
		}
	},
	alphadash: function(value, attr, computedState) {
		let msg = '';			
		
		if(value.search(/^[a-zA-Z0-9-_]+$/) == -1) {
			msg = 'Name can only contain letter, numbers and 1 hypen.'
		} else if(value.match(/-/g) == null || (value.match(/-/g) || []).length > 1) {
			msg = 'Display Name must contain 1 hypen between words. e.g products-create'
		}

		console.log(msg);

		return msg;
	},
	hyphen: function(value, attr, computedState) {
		console.log('hypen');
	},
});

return App;

});`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant