w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Summing text inputs in which the number of inputs changes based on a for loop
You'll have to examine all input elements and examine their name, checking for the prefix "hous". For example: var sum = 0; var elts = document.getElementsByTagName('input'); for( var i=0; i<elts.length; i++ ) { var elt = elts[i]; if( elt.id && elt.id.indexOf( 'hous' ) === 0 ) sum += Number( elt.value ); } console.log( sum ); This solution doesn't need jQuery. See it in action here: http://www.codepen.io/anon/pen/xmrGu

Categories : PHP

how to test angularjs app with angularjs e2e with multiple inputs with same ng-model
I figured it out. i need to use using to focus the scope. example using('div[filter="search.username"]').input("filter").enter("foo"); using('div[filter="search.ami"]').input("filter").enter("bar")

Categories : Javascript

Generate Unit Tests from a scenario table where inputs and expected results are specified
Well, w/o external tools the best you can do is most likely using macros. That's because you need to have TEST(GROUP_NAME, TEST_NAME) for each test case. It may not be the case. You may be fine with not having separate test case for each scenario or CppUTest may have support for programmatic way of adding test cases. In this case, you can create a method which takes vector of input-output-testcasename tuples. And will add testcases / run tests on each tuple. No macros needed. Something like that (pseudocode): typedef std::tuple<std::string, std::string, PriorityType, CompressType, ExpectedValueType> TestInfo; void RunTest(const TestInfo& testInfo) { // Assuming here you're OK with this kind of test cases separation std::cout << "Running test" << std::get<0&

Categories : C++

simple if else statement unit conversion
the if statement isn't doing quite what you want. To check for equality, use ==. = is assignment if unit == cm but you really want 'cm', since it is a string. You need to wrap it in quotes to let the runtime know you mean a string: if unit == 'cm' and finally, you need to output back to the user what the conversion was puts unit_number * a or even better result = unit_number * a puts "converting #{unit_number} to #{unit} is #{result}"

Categories : Ruby

simple if else statement unit conversion cm and in
gets will capture the stdin input including the trailing new line (enter), so unit won't be 'cm' and instead will be "cm ". You will need to remove the trailing " " using chomp: unit = gets.chomp You don't need to call to_s to the return value of gets because it is already a String, and the else statement should be elsif unit == 'cm' or else if unit == 'cm'.

Categories : Ruby

Is it possible to have AngularJS internationalize numeric inputs?
This may not be the answer you want, but maybe it helps you a little bit: JsBin: http://jsbin.com/iyulaj/1/ Using a directive you can take the data of the input, parse it and then put it to the $scope variable. Please see: http://docs.angularjs.org/api/ng.directive:ngModel.NgModelController ($parsers and $formatters. I took it from: Using angularjs filter in input element). The directive could search for a comma and replace it with a dot. It could look like this: angular.module('MyModule').directive('numberinput', function () { return { restrict: 'A', require: 'ngModel', link: function(scope, element, attrs, ngModelController) { ngModelController.$parsers.push(function(data) { //convert data from view format to model format

Categories : HTML

Count & print the checked inputs with AngularJS
JS: var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope) { $scope.lists = [ {'id':'1', 'name':'list 1', checked: true}, {'id':'2', 'name':'list 2'}, {'id':'3', 'name':'Macbook Pro'}, {'id':'4', 'name':'Dell Optiplex 755'}, {'id':'5', 'name':'Google Nexus S'} ]; $scope.$watch('lists', function(lists){ $scope.count = 0; angular.forEach(lists, function(list){ if(list.checked){ $scope.count += 1; } }) }, true); }); VIEW: <body ng-controller="MainCtrl"> <ul style="padding:10px;"> <input type="text" ng-model="fil.name" /> <li ng-repeat="list in lists | filter:fil"> <div style="margin-bottom:0;" class="checkbox"> <label> <in

Categories : Javascript

AngularJS - Binding the model to inputs that were not created with ng-repeat
http://www.bennadel.com/blog/2456-Grouping-Nested-ngRepeat-Lists-In-AngularJS.htm http://www.bennadel.com/blog/2421-Creating-AngularJS-Controllers-With-Instance-Methods.htm these 2 posts r different examples then what u would like to do but the show how to manipulate 2 lists or 1 into 2 with ngRepeat around too, i believe that after understanding this u'll have some good ideas.

Categories : Javascript

Counting number of inputs filled
You'll need to set the id attribute for the inputs as well as the name, otherwise getElementById works inconsistently cross browser. For instance: <input id="adverttexthead" name="adverttexthead" size="46" TYPE="text" onblur="countlines(this)" onkeypress="countlines(this)"> (Technically name is optional for purposes of document.getElementById, since id is accepted pretty universally, but you'll probably want to keep it so your forms submit correctly.) For more details, see: Document.getElementById() returns element with name equal to id specified

Categories : Javascript

Number inputs and ranges valueUpdate in Knockoutjs
It's because you have valueUpdate: 'afterkeydown' set. This causes the binding to try to update every time a key is pressed, and since you have a min of 512, trying to enter a value of 2 is going to fail. You can't enter 2048 because it tries to update after the first key. If you just take our that part of the binding it will work fine. <input type="number" data-bind="value: ram, attr: {max: 8192, min: 512, step: 1}" /> http://jsfiddle.net/Dt7Ka/118/

Categories : Javascript

How to limit total number of inputs to textExt plugin?
I do not know if this is the right way or not. But this worked for me. You can overwrite the core function using ext provided by the plugin and by having an additional function to check the elements already in the plugin. Your Plugin initialization should look like this $('#element').textext({ plugins : 'tags autocomplete', tagsItems : Sourcearray, ext: { tags: { addTags: function(tags) { if(checkLength()){ $.fn.textext.TextExtTags.prototype.addTags.apply(this, arguments); } } } } }) and the checkLength function should be like this function checkLength(){ if($("#element").next().children().l

Categories : Javascript

GLSL Instancing - Max number of inputs for vertex data?
OpenGL mandates implementations offer a minimum of 16 4-component vertex attributes. Therefore an index of 16 is not guaranteed to be supported by all implementations; see GL_MAX_VERTEX_ATTRIBS for more details. Your mat4 vertex attributes count as 4 4-component attributes, so an index of 14 is out of range on implementations that only support 16 4-component vertex attributes.

Categories : Opengl

Postgresql: Searching within arrays for an arbitrary number of inputs
You should use array operator <@ like this: SELECT * FROM users WHERE array['Wood','Doe'] <@ fullname; fiddle But what you really should do is get interested in full text search

Categories : SQL

How to add a div to the DOM in AngularJS unit tests?
This is how I managed to do it: beforeEach(inject( ['$compile','$rootScope', function(_$compile_) { var html = '<div class="smallcontainer-content"></div>'; angular.element(document.body).append(html); elm = angular.element('<form name="form"><input name="password" id="passwordInput" data-ng-model="password" size="25" type="password" maxlength="20" tabindex="1" autofocus data-my-password-check></form>'); $compile(elm)($rootScope); form = $rootScope.form; }] )); The important part here which adds the html to the document is the angular.element().append(). I found this in the midway testing code example of http://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-karma.html#testing-filters

Categories : Unit Testing

AngularJS: prevent empty (but dirty) form inputs from being included in AJAX post
The only way to set something to pristine is manually. That is, once a form has been touched, it's touched until you say otherwise. I would probably do a check in the update function for values in the form field as well as relying on pristine status.

Categories : Javascript

Model binding is not working when creating different type inputs dynamically with AngularJs ng-repeat
Ok so here is the html <li ng-repeat="prop in currentNode.props"> {{prop.name}}<input ng-model="prop.value" checked="{{prop.value}}" type="{{prop.type}}"></input> </li> and the controller code var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope) { $scope.currentNode = {name:'cube', props:[ {name:'displayName',value:'New Cube',type:'text'}, {name:'visible',value:'checked',type:'checkbox'} ]}; }); And here is plunk http://plnkr.co/edit/zy5Lh9 Hope it helps :)

Categories : Angularjs

How to format number inputs in rails form_for as the user types
HTML5 type="number" was no help in this situation. None of the jQuery plugins I found were helpful. But, it was super simple (not sure why I ever looked further than my own code) to implement. jQuery -> $("input.sum_number").change -> str = $(this).val() if str.charAt(0) == "." $(this).val("0#{str}") if str.charAt(str.length - 2) != "." $(this).val("#{str}.0")

Categories : Ruby On Rails

JavaScript: Calculating inputs (select input) and resulting a number
Your multiple select has no value selected on load, so you're trying to do : parseInt("") Which results as Not A Number Maybe you should add selected on the first option of your multiple select. <option value="1000" selected>Breakfast</option> You can also check for an empty string before calling parseInt

Categories : Javascript

AngularJS unit testing with ReSharper
Your hunch about ReSharper tripping over inline inject is right, it seems to expect function instead when it parses file to get list of tests. I've worked around by moving injects into either beforeEach or into the body of the it and that made ReSharper happy again. Btw, I've also added reference to jasmine.js at the top (before other references) to get rid of ReSharper's warnings about undefined Jasmine globals.

Categories : Angularjs

jQuery validation plugin, variable number of inputs, no console errors
You have the right idea, with collecting your fields in functions and then returning the appropriate objects. Unfortunately, rules only accepts an object as it's value, and same with groups. jQuery Validate does not understand setting those values to functions, which is why you're having nothing happen. Basically all your collecting of dynamic data needs to happen before the validate call. You will also have to return a bit less in your rules and messages objects: var $fields = $('.input-validate-integer'); //figure out groups var allFields = []; $fields.each(function() { allFields.push($(this).prop('name')); }); allFields = allFields.join(' '); var groupsObj = { number: allFields }; //setup rules allFields = []; var rules = {}; $fields.each(

Categories : Jquery

Fahrenheit and Celsius Bidirectional Conversion in AngularJS
I think the simplest, fastest, and most correct solution is to have a flag to track which field is being edited, and only allow updates from that field. All you need is to use the ng-change directive to set the flag on the field being edited. Working Plunk Code changes necessary: Modify the controller to look like this: function TemperatureConverterCtrl($scope) { // Keep track of who was last edited $scope.edited = null; $scope.markEdited = function(which) { $scope.edited = which; }; // Only edit if the correct field is being modified $scope.$watch('fahrenheit', function(value) { if($scope.edited == 'F') { $scope.celsius = (value - 32) * 5.0/9.0; } }); $scope.$watch('celsius', function(value) { if($scope.edited == 'C') { $scope.fahrenheit =

Categories : Database

Float to int number conversion in c++
The reason is because floating point values are stored in a more complicated way, partitioning the 32 bits into a sign, an exponent and a fraction. If these bits are read as an integer straight off, it will look like a very different value. The important point here is that if you create a union, you are saying that it is one contiguous block of memory that can be interpreted in two different ways. No where in this mechanism does it account for a safe conversion between float and int, in which case some kind of rounding occurs. Update: What you might want is float f = 10.25f; int i = (int)f; // Will give you i = 10 However, the union approach is closer to this: float f = 10.25f; int i = *((int *)&f); // Will give you some seemingly arbitrary value

Categories : C++

EmberJS unit test compared to AngularJS
I've found unit testing in Ember to be relatively straightforward. The are two things to make sure you understand in order to be successful writing Ember unit tests. First, you will sometimes need to provide an object with a container (e.g. an Ember.DefaultContainer instance) when you create it for testing. The container is the crux of Ember's dependency injection mechanisms. Definitely need to learn about it. Second, you will need to understand the Ember run loop in order to make sure the changes you make in your unit tests will propagate (e.g. computed properties with dependent keys becoming invalidated) before you assert that the new value is what you expect. I would highly recommend reviewing the unit tests for Ember itself. You will find many useful techniques there.

Categories : Unit Testing

Unit Testing AngularJS Directive that uses ng-switch
Try this: Directive app.directive('getData', function () { return { restrict: 'E,C', // Added E so <get-data></get-data> works replace: true, transclude: true, scope: { myData: '@' // Removed @myData since it's not needed here }, template: '<div ng-switch on="myData">' + ' <div ng-switch-when="4">Real Data</div>' + ' <div ng-switch-when="5">False Data</div>' + ' <div ng-switch-default class="grid">No Data</div>' + '</div>' } }); Tests describe('get-data test', function() { var $scope, $compile; beforeEach(function() { module('plunker'); inject(function($rootScop

Categories : Angularjs

Can we write unit test for AngularJS routeProvider?
Yes you can, is the quick answer and below is a little piece of code that can be used and extended to test that routes take you to the places you'd expect. I can elaborate on this a little more and my sources for how I learnt this in the first place, if you are interested? describe('Testing routes', function() { beforeEach(module('windscreens')); var location, route, rootScope; beforeEach(inject( function( _$location_, _$route_, _$rootScope_ ) { location = _$location_; route = _$route_; rootScope = _$rootScope_; })); describe('Login route', function() { beforeEach(inject( function($httpBackend) { $httpBackend.expectGET('login') .respond(200); })); it('should load the login page on successful load of /login',

Categories : Unit Testing

Unit testing in AngularJS with mock $resource
Ended up using this example https://github.com/tebriel/angular-seed/commit/b653ce8e642ebd3e2978d5404db81897edc88bcb#commitcomment-3416223 Basically: describe('controllers', function(){ beforeEach(module('myApp.controllers')); it('should ....', inject(function($controller) { //spec body var myCtrl1 = $controller('MyCtrl1'); expect(myCtrl1).toBeDefined(); })); it('should ....', inject(function($controller) { //spec body var myCtrl2 = $controller('MyCtrl2'); expect(myCtrl2).toBeDefined(); })); });

Categories : Javascript

How to write unit test for AngularJS model
You need to run a beforeEach in your test to inject the model instance and then assign it to a variable which you can then re-use through out your tests. var AboutModel; beforeEach(inject(function (_AboutModel_) { AboutModel = _AboutModel_; })); You can then access your getter like so: AboutModel.getParagraphs(); I have tweaked your original model slightly as I feel it reads a little better (my preference): 'use strict'; angular.module('anExampleApp') .factory('AboutModel', function () { var _paragraphs; // Public API here return { setParagraphs: function (newParagraphs) { _paragraphs = newParagraphs; }, getParagraphs: function () { return _paragraphs; } }; }); And then for testing I would use a combination of the s

Categories : Unit Testing

AngularJs Unit Tests with Jasmine and RequireJs
I had loads of issues getting angular, mocking and require to play nice with jasmine. In the end the answer was obvious you need to boot jasmine up and ensure it's fed your specs. This is a cut down version of what I did, I hope it helps to get you on the right track. /* this would be 'main'*/ require.config({ paths: { 'jasmine-boot': 'lib/jasmine/boot', 'jashtml': 'lib/jasmine/jasmine-html', 'jasmine': 'lib/jasmine/jasmine', 'angular': 'lib/angular', 'angular-mocks': 'lib/angular-mocks', 'app': 'src/app', 'test': 'spec/first.spec', }, shim: { 'jashtml': { deps: ['jasmine'] }, 'jasmine-boot': { deps: ['jasmine', 'jashtml'] },

Categories : Angularjs

Count the current number of inputs with a specific property after a function has run which has changed these properties
You are comparing the same set of elements over and over again. You need to re-select the ones that you need during each check. Change required.each(function() To $([required]).each(function() You are selecting all the element and then looping through them regardless of the properties that they now have. You want to have jQuery re-select the elements that now have the required property so that you get an updated list. This should then perform as you expect.

Categories : Jquery

AngularJS service unit test fails on toEqual
toEqual will be checking for reference equality, that is the alerts object is THE SAME object as mockAlerts. What you want to check for is object equality. There are a few ways of doing this. First you could convert your objects to json expect(JSON.stringify(alerts)).toEqual(JSON.stringify(mockAlerts)); That will probably work most of the time, but it does depend on the serializer treating the objects exactly the same way. Another way you could do it is to use angular.equals. expect(angular.equals(alerts, mockAlerts).toBeTruthy(); Which probably doesn't read as well but should work nicely.

Categories : Javascript

details on mock $compileProvider in AngularJS unit tests
Since Angular 1.2 the method has been changed to $compileProvider.aHrefSanitizationWhitelist() This answer came from here: Angular changes urls to "unsafe:" in extension page

Categories : Angularjs

Unit testing a directive that defines a controller in AngularJS
Create the element in karma, then use the .controller() function with the name of your directive to grab the controller. For your example, replace the last couple of lines with these: elem = angular.element('<div example-directive></div>'); $compile(elem)($rootScope); var controller = elem.controller('exampleDirective'); Note, that given how you defined your directive, it should be by attribute, and not as an element. I'm also not 100% sure, but I don't think you need the scope.$digest; usually I just put anything that needs to be applied into a scope.$apply(function() {}) block.

Categories : Unit Testing

How to Unit Test Isolated Scope Directive in AngularJS
I'm not sure it's possible with isolate scope (although I hope someone proves me wrong). The isolate scope that gets created in the directive is, well, isolated, so the $watch method in the directive is different from the scope that you're spying on in the unit test. If you change scope: {} to scope: true, the directive scope will inherit prototypically and your tests should pass. I guess this isn't the most ideal solution, because sometimes (a lot of the time), isolate scope is a good thing.

Categories : Javascript

Effectively unit test an AngularJS directive which is manipulating the DOM
I made a pull request that makes your tests run. https://github.com/bennyjo/angular-smoothscroll/commit/e660a8e1a4497907a9c74d9e359f2bbfa0b8326c Basically the problem was that there was no space that the window could be scrolled into. Hence, no scrolling was possible and the tests failed correctly. I added some height on the body element to make the window scrollable. $('body').height(window.innerHeight*2).append @target I also did reset the scroll position before each test. If we don't do this the second test will fail. window.scrollTo(0, 0);

Categories : Javascript

Unit Testing an AngularJS Controller With CoffeeScript and Karma
As noted above: Figured it out...the page object that I was trying to reference was declared elsewhere. This example was abstracted from a chunk of a platform that multiple developers are working on. The solution was simply to set the page object to empty and the test passed successfully.

Categories : Angularjs

Multiple decimal string conversion to number
Try: CAST(value AS Decimal(15,2)) If you're just concerned with the "look" of the numbers, you can use: SELECT TO_CHAR(num, '999,999,990.00') FROM MyTable

Categories : SQL

Number representation similar to base conversion
I don't really understand the point of your transformation, but don't you just try to convert n-1? base_convert ($number_to_convert - 1, 10, 36); EDIT: If 1base 10 transforms to 0your special base – what character will you use for 0? I don't think your system can be used for valid notations of numbers. EDIT2: I've probably understood the question in a too mathematical way. Please refer to @Paulpro's answer for a pragmatic solution to the problem (that isn't actually converting to another base but returning a string representing the input number).

Categories : PHP

Getting error regarding slice during Karma/AngularJS unit test config
I had the same problem, but I was running this in Cygwin. I don't know if you were. I first uninstalled and reinstalled nodejs. When I brought up the rxvt window again to try installing karma, it failed with this: /c/Program Files/nodejs/npm: line 2: $' ': command not found /c/Program Files/nodejs/npm: line 4: $' ': command not found /c/Program Files/nodejs/npm: line 5: syntax error near unexpected token `$'in '' 'c/Program Files/nodejs/npm: line 5: `case `uname` in This is apparently because of my using it in Cygwin, although I don't know why I didn't get this error before. The following talks about this: https://github.com/isaacs/npm/issues/3710 . So, I then just opened up a plain "cmd" window, and I found that the package install completed, and "karma init" worked well enough to

Categories : Angularjs

Unit testing AngularJS with $httpBackend gives "Error: Unexpected Request"
My first thought is that something is making a request when you instantiate your controller. Maybe try adding the $httpBackend.flush() after your controller declaration line and see if that solves it. Also, should your $scope.$digest be after the $httpBackend.flush instead of before?

Categories : Angularjs

Unit testing directives without unnecessary dependencies in module AngularJS
You have to mock them. For example, you can create a module called mocks with a d with the services or directives you want to mock. You then load it with beforeEach(module('mocks')); and your calls from the test suite to whatever service you have in mocks will be using the dummy implementation. You can put this mock module in your test folder, like /test/lib/my-mocks.js (next to angular-mocks.js, if you're using angular-seed). Lastly, you include it in karma.conf.js: files = [ 'app/lib/jquery/jquery-1.9.1.js', JASMINE, JASMINE_ADAPTER, 'test/lib/jasmine-jquery.js', 'app/lib/angular/angular.js', ... 'test/lib/myproject/my-mocks.js', ... ]; Another approach is using jasmine spies. For example: spyOn($location, 'absUrl').andCallFake(function (p) { return 'http://lo

Categories : Angularjs



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