w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
angularjs validate input and prevent change if invalid
You could always listen to the keypress event and prevent the character from making it through. Here is a plunker var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope) { $scope.name = 'World'; $scope.validValues = ['a','1','2']; }); app.directive('myValidator', function ($parse) { return { scope: { validValues: '=validValues' }, link: function (scope, elm, attrs) { elm.bind('keypress', function(e){ var char = String.fromCharCode(e.which||e.charCode||e.keyCode), matches = []; angular.forEach(scope.validValues, function(value, key){ if(char === value) matches.push(char); }, matches); if(matches.length == 0){ e.preventDefault();

Categories : Javascript

AngularJS - changing input validity from controller
Passing in the form's password control to checkPasswordCriteria and modifying it inside of that function would do the trick: <div> <label class="control-label screen-reader-text" for="password">Password</label> <div class="controls relative mrl"> <input name="password" id="password" ng-model="formModel.password" ng-change="checkPasswordCriteria(form.password)" required class="immediate-help large-field" type="password" placeholder="Enter new password"> </div> </div> And inside checkPasswordCriteria, just set the validity on the control based on the response: $scope.checkPasswordCriteria = function (passwordControl) { if (!checkingPasswordCriteria) { checkingPasswordCriteria = true; // Simulating a servic

Categories : Angularjs

HTML5/JS/jQuery: On invalid input, mark a different (arbitrary) element as invalid
Try the below code. You are getting that error because jQuery returns an array of selected objects and since setCustomValidity is supported by native input elements and not jquery objects, you are seeing that error. $('#newpassword1, #newpassword2').each(function() { this.setCustomValidity(errorMessage) });

Categories : Javascript

AngularJS: how to change scope in one controller with trigger in the other controller
The code Well, I think this is not the best solution, but it is possible for your problem. Instead of just changing the value itself, you have to create an object before the return statement in the factory. var obj = {} And then you just change a property of this object: if( typeof(update)==='undefined') { obj.val = defaultValue; } else { obj.val = update; } And return the object: return obj; The other controller can be left unaffected, however you have to change your html: You have to put in {{object.val}} in order to listen to changes. http://plnkr.co/edit/rjsrkbaQ8QyWGGFI9HYl?p=preview Why does this work? It is quite simple: In javascript, if you call a function with a primitive return value like a string (yes, strings CAN be primitives in javascript), it is just

Categories : Javascript

Dynamically add existing controller into another controller with AngularJS
Don't try to access the DOM from controller code. Never. It is very bad practice which breaks AngularJS conventions and eventually provides you with bad architecture. This also means you should not create any DOM elements manually from a controller. Better to manipulate with the scope itself, not with its visual representation. You can add new models to scope on your button's click, which will be translated to new elements by ng-repeat directive, each with its own controller (remember controllers are instances, not singletons, so that they have separated life cycles). You might want to make use of <script type="text/ng-template"> and ng-include here instead of hidden divs. Try to avoid using $rootScope when possible - it is global state which can be dangerous. It might look like

Categories : Angularjs

angularjs controller not loaded (not using ng-controller in view)
You are missing ng-view in your index.html. ngView is a directive that complements the $route service by including the rendered template of the current route into the main layout (index.html) file. Every time the current route changes, the included view changes with it according to the configuration of the $route service. <body id="splash" ng-view> </body>

Categories : Angularjs

Can an AngularJS controller inherit from another controller in the same module?
I think,you should use factory or service,to give accessible functions or data for both controllers. here is similar question ---> AngularJS controller inheritance

Categories : Angularjs

Angularjs. Accessing attributes from an AngularJS controller
There's probably a better way to do this... pass $event to your controller function <a data-ng-click="save(book, $event)" class="btn">Submit</a> and then use traversal methods to find the img tag and its src attr: $scope.save = function (book, ev) { console.log(angular.element(ev.srcElement).parent().find('img')[0].src); ... Update: the better way is to create a directive (like @mitch did), but I would use = binding in an isolate scope to update a src property in the parent scope. (The = makes it clear that the directive may alter the scope. I think this is better than having a directive add a method or a property to the controller's scope "behind the scenes".) <div ng-controller="MyCtrl"> <img save-image book="book1" src="http://placehold.it/350

Categories : Angularjs

How can I add a class to an input if the input is changed with AngularJS?
Take a look at this jsfiddle: http://jsfiddle.net/hNrEV/2/ The main idea is using $scope.$watch to watch for changes to the input box. I gave it an id of rowTitle, and used a directive called watchRowTitle that watches for changes to $scope.row.title, and adds a class 'red' that colors the text red whenever the text in the input box is equal to 'wrong title'. It is probably good practice to do DOM manipulation in directives. Here, the watchRowTitle directive returns an object with 4 keys: template - the html that replaces the watch-row-title tag. we dont need this here scope - Here we make use of an isolated scope. Basically, the '=' establishes a 2-way data binding between between scope.title inside the watch-row-title directive and the $scope.row.title value inside the MyCtrl control

Categories : Angularjs

Invalid controller specified (error) when trying Propel Query
It seems that you don't have access to the problem, because exceptions are catched by Zend_Controller_Plugin_ErrorHandler. You have this exception because you have no ErrorController, and the handler is trying to call it. You may have the exception details in your error logs. In order to watch the error message., you can put this code in your bootstrap : $front = Zend_Controller_Front::getInstance(); $front->throwExceptions( false ); or in the application.ini : resources.frontController.throwexceptions = false (very useful in developpement configuration) However, if you use the errorHanlder, you should implement an ErrorController

Categories : PHP

Set input as invalid
In the HTMLInputElement interface, there is no such property as valid or invalid. You can use the setCustomValidity(error) method with native form validation. As for your script: $(document).ready(function() { $('input[name=pass2]').keyup(function () { 'use strict'; if ($('input[name=pass]').val() === $(this).val()) { $('#pass_hint').html('match'); $(this)[0].setCustomValidity(''); } else { $('#pass_hint').html('mismatch'); $(this)[0].setCustomValidity('Passwords must match'); } }); }); View the jsFiddle in an HTML5 complaint browser.

Categories : Jquery

AngularJS validation ng-invalid class only after submit
Demo <input type="email" name="email" ng-model="formData.email" required /> <span ng-show="(myForm.email.$dirty || submitted) && myForm.email.$error.required"> Email is required </span> Use $dirty flag to show the error only after user interacted with the input:

Categories : Javascript

Exception information:Message: Invalid controller specified (index)
I think you need to create class Agreements_IndexController with method public function indexAction() { } and put it in here application/modules/agreements/controllers/IndexController.php. And don't forget to create view file, application/modules/agreements/views/sctipts/index/index.phtml. With basic config it should help.

Categories : PHP

Checking for invalid input
You're displaying the message for every line that does not contain the ID. What you must do is display it if no line contains the ID. And you'll know that only when you have found the ID (which means that the ID exists), or when you have read all the lines without finding it (which means that the ID doesn't exist) So, you should use a boolean variable idFound initialized to false, and loop until it has become true, or the end of the reader has been met. Then after the loop, you can tell if the ID has been found by examining the value of this boolean variable, and display the message if it's still false. I won't provide code, because you should be able to figure that out by yourself. EDIT: your updated code has two bugs: if (s.split(",")[1].contains(infoToRemove)) { continue; }

Categories : Java

Set invalid input to initial value
Keep a Hidden Field which will be filled with the initial value. Suppose you have value "4321" to be shown in the text box. Just load that value Into the textbox as well as in hidden field. Now on Change of this value when you are making an AJAX request, So if the value is correct just update the hidden field with the correct value else just replace the value in the textbox with the value in the hidden field. Hope this helps... Sample Code: <input type="text" id="textbox" value="1234"/> <input type="hidden" id="hidden" value="1234"/> $('#textbox').change(function(){ if(parseInt($('#textbox').val())) { $('#hidden').val($('#textbox').val()); //Make AJAX request } else { $('#textbox').val($('#hidden').val());

Categories : Jquery

How should a SQL CLR UDT handle invalid input?
Throwing an ArgumentException seems to be the correct way - see Coding User-Defined Types, and specifically the Parse Validation Example: [SqlMethod(OnNullCall = false)] public static Point Parse(SqlString s) { if (s.IsNull) return Null; // Parse input string to separate out points. Point pt = new Point(); string[] xy = s.Value.Split(",".ToCharArray()); pt.X = Int32.Parse(xy[0]); pt.Y = Int32.Parse(xy[1]); // Call ValidatePoint to enforce validation // for string conversions. if (!pt.ValidatePoint()) throw new ArgumentException("Invalid XY coordinate values."); return pt; }

Categories : Sql Server

How to prevent crashing from a invalid input in C#
Use TryParse instead: private void btnResult_Click(object sender, EventArgs e) { int a, b; if (int.TryParse(first, out a) && int.TryParse(second, out b)) { int c = a + b; txtResult.Text = c.ToString(); } else { MessageBox.Show("Invalid Input!"); } } Or perhaps a better method would be to trap the error when the user first inputs the data: public partial class frmAdd : Form { int first; // changed to int int second; private void btnFirst_Click(object sender, EventArgs e) { if (!int.TryParse(txtNumber.Text, out this.first)) { MessageBox.Show("Invalid Input!"); } } private void btnSecond_Click(object sender, EventArgs e) { if (!int.TryParse(txtNumber.T

Categories : C#

Unable to PUT with Angularjs $http.put, receive Invalid JSON primitive
Turns out I had defined a global transform for $http and it was using jQuery.param() to encode. Once I removed this it work perfectly. var app = angular.module('app', ['ui.select2', 'ui.bootstrap']) .config(['$httpProvider', function ($httpProvider) { delete $httpProvider.defaults.headers.common['X-Requested-With']; $httpProvider.defaults.transformRequest = function (data) { if (data === undefined) { return data; } return $.param(data); }; }]);

Categories : C#

Set input invalid when typeahead-editable is false
The typeahead directive from http://angular-ui.github.io/bootstrap/ has already support for limiting inputs to matches (in other words, people can bind to model only values available as matches in the typeahead popup). You can do this by simply setting typeahead-editable='false' attribute. Please note that setting this attribute to false will not prevent people from typing-in invalid values. It will just make sure that a corresponding input is marked as invalid and a provided value is not bound to the model.

Categories : Angularjs

How do I prevent crashing from invalid user input?
Use Int32.TryParse() and handle the case when it's not an integer. The return value indicates whether the operation succeeded. For more information see http://msdn.microsoft.com/en-us/library/system.int32.tryparse.aspx

Categories : C#

Display text error when invalid input?
You can set values for visibility of a view,for example gone,... .Check the value and states of other views and change the visibility of textview in corresponding it. You can hide or show views using setVisibility(int) in java code. Documents in about Animation say: Starting with Android 3.0, the preferred way of animating views is to use the android.animation package APIs. These Animator-based classes change actual properties of the View object, such as alpha and translationX. This behavior is contrasted to that of the pre-3.0 Animation-based classes, which instead animate only how the view is drawn on the display. In particular, the ViewPropertyAnimator class makes animating these View properties particularly easy and efficient. Alternatively, you can use the pre-

Categories : Android

Yii CDbException.. invalid input syntax for integer: "1,075"
The issue was actually because used number_format() function to a primary key and later in a code section it inputs the formatted number to search query.. i.e select * from user where id = 1,075 (instead of id = 1075) Changing the number_format() function to apply only on selected areas worked.

Categories : SQL

How to unit test "console.readLine" for invalid input?
You can set Console.In to a given text reader using SetIn: var sr = new StringReader("Invalid int"); Console.SetIn(sr); int? parsed = MethodUnderTest(); Assert.IsNull(parsed);

Categories : C#

Caller Input Exception: Invalid Signature amazon
There are three things of note to keep track of while forming your signature/URL... 1.It seems that the parameter "transactionAmount" is necessary for a valid Co-branded UI Pipeline, even though there's no specific instruction alluding to the issue. 2.If any of your parameters have/had spaces in them, and you tried to use html_build_query() in all but the latest (5.4) version of PHP, you would be given an encoding scheme that featured "+" marks for spaces instead of "%20" which is what Amazon appears to like. My code above takes care of that by implementing rawurlencode() on the entire parameter array. 3.The ordering of the parameters is paramount in the construction of the signature. The keys (not the values) need to be in case-insensitive alphabetical order. It's also worth noting tha

Categories : PHP

PG COPY error: invalid input syntax for integer
ERROR: invalid input syntax for integer: "" "" isn't a valid integer. PostgreSQL accepts unquoted blank fields as null by default in CSV, but "" would be like writing: SELECT ''::integer; and fail for the same reason. If you want to deal with CSV that has things like quoted empty strings for null integers, you'll need to feed it to PostgreSQL via a pre-processor that can neaten it up a bit. PostgreSQL's CSV input doesn't understand all the weird and wonderful possible abuses of CSV. Options include: Loading it in a spreadsheet and exporting sane CSV; Using the Python csv module, Perl Text::CSV, etc to pre-process it; Using Perl/Python/whatever to load the CSV and insert it directly into the DB Using an ETL tool like CloverETL, Talend Studio, or Pentaho Kettle

Categories : Postgresql

Operator Overloading to show error on invalid input
If this is not a template, NO! Compile time error will be identified by compiler for what it can detect at compile time, so if dimensions of matrix will be identified at runtime, compiler can't know anything about it and you must identify error with an exception or something like that. But if dimensions of matrix will be identified by template arguments compiler can know them and generate errors at compile time, but using this approach you can't get dimension from the user at runtime.

Categories : C++

AngularJS script gives error ReferenceError Invalid left-hand side in assignment
Seems like this is problematic : $scope.testService() = function() { may be you should try to change it like this: $scope.testService = function() {

Categories : Javascript

play framework validation binding invalid input value with POJO
The behavior that you see in the update method is the way Play works! Here is the relevant section from the documentation : ... When Play finds the id field, it loads the matching instance from the database before editing it. The other parameters provided by the HTTP request are then applied. So in your case, when the sort property is null during an update, the value in the database is used. Now if I were to try to achieve what you are trying to do, I would propably do it this way : In my model @Required @CheckWith(IntegerCheck.class) public int sort; // using primitive here to avoid null values. static class IntegerCheck extends Check { public boolean isSatisfied(Object model, Object sort) { int fieldValue = (int) sort; // here you have the value as int

Categories : Validation

Tooltip Text for Invalid Input Pattern "You must use this format: [blank]"
Try using the title attribute to describe what you want it to say: <input id="institution_threshold_days" type="text" placeholder="0-9999" pattern="^[0-9]{1,4}$" title="Please enter a number less than 10000." /> http://msdn.microsoft.com/en-us/library/ie/hh673544(v=vs.85).aspx#custom_validation_error_messages

Categories : Regex

Which exception to throw for invalid input which is valid from client perspective
Exceptions should be used to catch errors in program flow ("what happens inside") , not for input validation. I wouldn't throw an exception at all. Think about it, this is not what "exception" means as it is completely normal for the user to input two lines with equal slopes.

Categories : Java

Java: Easier Way to Re-prompt user for input when invalid data is entered
If you are just worried about the return that is not used and double checking temp you can do something like public static int getInput() { while(true) { System.out.println("Answers must be between 1 and 15"); temp = reader.nextInt(); if(temp >=1 && temp <= 15) { return temp; } else { System.out.println("Please enter a valid value"); } } }//End of getInput method

Categories : Java

jQuery Validator invalid input fields disappear after successful submit
errorClass:'control-group error', errorElement: 'div.control-group', highlight: function (element, errorClass) { $(element).parents("div.control-group").addClass(errorClass); }, unhighlight: function (element, errorClass, validClass) { $(element).parents(".error").removeClass(errorClass); }

Categories : Javascript

knockout-validation change input background color on invalid model
Knockout-Validation plugin adds an error class to the elemnts which are not valid. All you need to do is set the background color for that class: .error { background: yellow; } If you need to change the element error class you cand do that too. More info in the configuration section of the documentation (https://github.com/Knockout-Contrib/Knockout-Validation/wiki/Configuration).

Categories : Knockout Js

AngularJS $q.all for all queries in controller
Encapsulate your ajax logic in a service var services = angular.module('myServices', []); services.factory('AjaxLoader', ['$q', function($q) { return { doAjax : function() { var d = $q.defer(); $scope.userOrders = UserOrders.query({id:$routeParams.id}, function(result) { d.resolve(result); }); $q.all([d.promise]); } } }); In your controller. var controllers = angular.module('myControllers',[]); controllers.controller('Controller', ['AjaxLoader', function(AjaxLoader) { AjaxLoader.doAjax().then(function() { $("#loading").hide(); }); }]);

Categories : Angularjs

AngularJS Getting Setting more than one controller
You probably won't want to have a controller per entity. You're controller here maps to a scope object. The scope is then bound to a view - keeping them in sync. So if your view displays a recipe (i.e name/description), it might also have a child property ingredients ($scope.recipe.ingredients). You're controller will manage this 'recipe' object, and also provide methods to modify/retrieve/manage it. Say for example you want to save the $scope.reciepe object to your FireBase store - you can inject a service into your controller, and then make a $http call to 'put' that object into your db. A brief conceptual overview of control See more at https://docs.angularjs.org/guide/controller

Categories : Angularjs

Having more than one controller in a view in AngularJS
Yes you can use multiple controller in one view with ng-controller It's not a bad practice. If you think it's a component that you can separate to a directive, it would be better. Since directive is all about a component that can do a specific task and it has it's own controller and scope. And It's easier to test too !

Categories : Javascript

Controller not firing in AngularJS
You are creating the module 'TurkApp' twice, thereby losing the configuration registered with the first module: angular.module('TurkApp', ['ngCookies']) When you include the second parameter to the angular.module function, it creates the module. If you omit the second parameter, it assumes the modules exists and "extends" it. Change: angular.module('TurkApp', []) to: angular.module('TurkApp') See the usage section here - http://docs.angularjs.org/api/angular.module

Categories : Javascript

AngularJS Controller execute twice
2nd Answer, the technical answer is that the $routeProvider caused it, i dont know why but when i change my "master" html to this: <div ng-app="VODCatalogModule" ng-controller="VODViewsController" ng-switch on="templateUrl"> <div class="wrapper" ng-switch-when="TopLevelView" ng-include="'/_catalogs/masterpage/html/VODCatalog_TopLevelView.html'" ng-controller="VODCatalogController"></div> <div class="wrapper" ng-switch-when="LowLevelView" ng-include="'/_catalogs/masterpage/html/VODCatalog_LowLevelView.html'" ng-controller="VODCatalogController"></div> </div> the controller finally was created only once. the conclusion is that if you gonna work with the $routeProvider then its only good for basic routing, anything more complex require work. the mo

Categories : Angularjs

angularjs - can not find the controller
mainApp should read var myModule = angular.module('mainAPP', ['subAPP']); myModule.config([ /******/ '$routeProvider', function ($routeProvider) { $routeProvider.when('/test', { templateUrl: 'components/test/test-list.html', controller: 'SubAppCtrl' }); } ]); note quotes around the controller name.

Categories : Angularjs

angularjs access value of one controller from another
Here's a simple solution: <div ng-init='model={ person: "", car: "" }'> <div ng-controller="aCtrl"> <input type="text" ng-model="model.person" /> <button type="button" ng-click="Search()">XXX</button> </div> <div ng-controller="bCtrl"> <input type="text" ng-model="model.car" /> </div> </div> Simply go one step higher on the $scope and set your data on the parent scope. Notice that I updated the values bound to your inputs to reference properties of the new model object. By doing this, you reference an object on that parent scope rather than scalars, so that the reference to that object gets prototypically inherited by the child scopes. If this doesn't make much sense, the tl;dr version is: Generally speaking,

Categories : Angularjs



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.