Format input value in Angularjs

Here is working example where we use unshift: angular.module(‘myApp.directives’, []).directive(‘format’, [‘$filter’, function ($filter) { return { require: ‘?ngModel’, link: function (scope, elem, attrs, ctrl) { if (!ctrl) return; ctrl.$formatters.unshift(function (a) { return $filter(attrs.format)(ctrl.$modelValue) }); ctrl.$parsers.unshift(function (viewValue) { var plainNumber = viewValue.replace(/[^\d|\-+|\.+]/g, ”); elem.val($filter(attrs.format)(plainNumber)); return plainNumber; }); } }; }]); The HTML seems: <input type=”text” ng-model=”test” … Read more

How to restrict number of characters that can be entered in HTML5 number input field on iPhone

Example JS function limit(element) { var max_chars = 2; if(element.value.length > max_chars) { element.value = element.value.substr(0, max_chars); } } HTML <input type=”number” onkeydown=”limit(this);” onkeyup=”limit(this);”> If you are using jQuery you can tidy up the JavaScript a little: JS var max_chars = 2; $(‘#input’).keydown( function(e){ if ($(this).val().length >= max_chars) { $(this).val($(this).val().substr(0, max_chars)); } }); $(‘#input’).keyup( function(e){ … Read more

Angular 5 file upload: Failed to set the ‘value’ property on ‘HTMLInputElement’

In my case I just removed the formControlName: <input type=”file” (change)=”onFileChange($event)”> And .ts: onFileChange(event) { const reader = new FileReader(); if (event.target.files && event.target.files.length) { const [file] = event.target.files; reader.readAsDataURL(file); reader.onload = () => { this.data.parentForm.patchValue({ tso: reader.result }); // need to run CD since file load runs outside of zone this.cd.markForCheck(); }; } }

Phone mask with jQuery and Masked Input Plugin

Try this – http://jsfiddle.net/dKRGE/3/ $(“#phone”).mask(“(99) 9999?9-9999”); $(“#phone”).on(“blur”, function() { var last = $(this).val().substr( $(this).val().indexOf(“-“) + 1 ); if( last.length == 3 ) { var move = $(this).val().substr( $(this).val().indexOf(“-“) – 1, 1 ); var lastfour = move + last; var first = $(this).val().substr( 0, 9 ); $(this).val( first + ‘-‘ + lastfour ); } });

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)