|
|
Hi, I am trying to mask a Phone number in a input field, can somebody please help me in this regards. Here is my code for the html (or hbs file)
<label class="control-label">Phone</label>
{{masked-input mask='(999) 999-9999'
value=model.Address.Phone
input-format='regex'
input-filter='\(*[0-9]{3}\) [0-9]{3}-[0-9]{4}'
input-filter-message='Phone number is not valid.'
class='form-control phone masked'
maxlength="14"}}
</div>
And my component definition is as below:
export default () => {
IMS.registerComponent("masked-input", {
tagName: 'input',
attrParams: ['required', 'title', 'name', 'placeholder'],
loaded: false,
prop: Ember.observer(
'required',
'title',
'name',
'placeholder',
'value',
function () {
var scope = this;
$(this.element).val(Ember.get(scope, 'value'));
var stamp = new Date();
if (Ember.get(scope, 'loaded') == true) {
var element = $(this.element);
var attrs = Ember.get(this, 'attrParams');
attrs.forEach(function (attr) {
var value = Ember.get(scope, attr);
if (value == '' | value == null) {
element.removeAttr(attr);
} else {
element.attr(attr, value);
}
})
}
}),
observeMask: Ember.observer('mask', function () {
var scope = this;
$(this.element).inputmask({
mask: Ember.get(scope, 'mask')
});
}),
didInsertElement: function () {
var scope = this;
setTimeout(function () {
var value = Ember.get(scope, 'value');
var element = $(scope.element);
var change = function () { Ember.set(scope, 'value', element.val()); }
element.val(Ember.get(scope, 'value'));
element.attr('type', 'text');
element.change(change);
Ember.set(scope, 'loaded', true);
scope.observeChanges();
element.inputmask({
mask: Ember.get(scope, 'mask')
});
element.attr('input-format', Ember.get(scope, 'input-format'));
element.attr('input-filter', Ember.get(scope, 'input-filter'));
element.attr('input-filter-message', Ember.get(scope, 'input-filter-message'));
}, 250);
}
})
}
Can somebody please help me why is it not working? Thanks in advance.
|
|
|
|
|
My assignment asks for this step that I mentioned in the title, but I have 3 days trying to make it,
I don't know how to do it.here is my code in GitHub:-
https://github.com/HamzaSamiHussein/BusMall/tree/busMall
|
|
|
|
|
Create 2 objects with different fields. Write a code that moves both objects and skincatenates all array fields that will be stored in the variable 'allArrays = [...]'. Calculate the sum of the number elements in the arrays.
* Objects only single level
|
|
|
|
|
|
skincatenating is going to be the difficult bit.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
There is more than one way to skin a cat.
|
|
|
|
|
Does anyone know a good source on DOM usage?
|
|
|
|
|
|
I'm working on a project in which i'm capturing map screenshot (using dom-to-image library) and sending it to an external api which is returning back some co-ordinates(x,y,w,h) after processing the sent image. These co-ordinates(rectangles) i'm trying to draw on leaflet.
As the captured image size is bigger than width and height of captured area (don't know why), I need to do scaling the co-ordinates.
Now the problem is Leaflet rectangles are not drawing on accurate position which external API is returning.
However, I'm sure that the external API is returning correct co-ordinates (x,y,w,h) with correspond to send image's width & height.
Something wrong i'm doing on scaling coordinates.
Below is the code snippet i'm trying:
domtoimage.toPng(document.querySelector("#map"))
.then(function (dataUrl) {
var boundsOnly = map.getBounds();
let topLeft = boundsOnly.getNorthWest();
let topRight = boundsOnly.getNorthEast();
let bottomLeft = boundsOnly.getSouthWest();
let bottomRight = boundsOnly.getSouthEast();
var currBBOXpoints = { x1y1: map.latLngToLayerPoint(topLeft), x2y2: map.latLngToLayerPoint(topRight), x3y3: map.latLngToLayerPoint(bottomRight), x4y4: map.latLngToLayerPoint(bottomLeft) };
var pW = currBBOXpoints.x2y2.x - currBBOXpoints.x1y1.x;
var pH = currBBOXpoints.x3y3.y - currBBOXpoints.x1y1.y;
currBBOXpoints.pW = pW;
currBBOXpoints.pH = pH;
var i = new Image();
i.onload = function () {
$.ajax({
type: 'post',
url: '/externalapi',
data: JSON.stringify(dataUrl),
contentType: "application/json",
dataType: "json",
success: function (resultData) {
resultData["iW"] = i.width;
resultData["iH"] = i.height;
resultData["currBBOXpoints"] = currBBOXpoints;
drawRects(resultData);
}
});
};
i.src = dataUrl;
});
function drawRects(rectData) {
var scale = Math.max(rectData.currBBOXpoints.pW / rectData['iW'], rectData.currBBOXpoints.pH / rectData['iH']);
var shifted_x = rectData.currBBOXpoints.pW / 2 - rectData['iW'] / 2 * scale;
var shifted_y = rectData.currBBOXpoints.pH / 2 - rectData['iH'] / 2 * scale;
rectData.od.forEach(rc => {
var modifiedX = Number(rc['x']) * scale + shifted_x;
var modifiedY = Number(rc['y']) * scale + shifted_y;
var modifiedW = (modifiedX + rc['w'])
var modifiedH = (modifiedY + rc['h'])
let point3 = map.layerPointToLatLng(L.point(modifiedX, modifiedY));
let point4 = map.layerPointToLatLng(L.point(modifiedW, modifiedH));
var rectBounds = [[point3.lat, point3.lng], [point4.lat, point4.lng]];
var boundingBox = L.rectangle(rectBounds, { color: "yellow", weight: 1, name: "rect", fillOpacity: 0.10 });
map.addLayer(boundingBox);
});
}
|
|
|
|
|
Maybe it has something to do with the monitors screen resolution, dpi, 100% vs 125% view magnification.
When you draw an image is say Illustrator, at 100 x 100, it's 100 pixels x 100 pixels. But when you output that Illustrator file to JPEG or PNG, and then load it up, we think it's still 100 x 100, but it may actually be smaller or larger on the screen.
look at the scale, try a 1 to 1 scale manually.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
let sum = () => {
a=prompt();
b=prompt();
return a+b;
}
console.log(sum());
I don't understand why the hell concatenate two numbers instead of sum them. Less understand why only a summary is a problem and multiply, extraction, dividing is OK. Can you help me please?
|
|
|
|
|
Most likely because the prompt returns a string rather than an integer. You need to convert the input to integers with parseInt :
a = parseInt(prompt());
b = parseInt(prompt());
|
|
|
|
|
Thank you! I'm very grateful
|
|
|
|
|
|
let object_literal1 ={
fullName : "shanu1",
name : () => {
return this.fullName
},
greeting : (message) => console.log(message + " "+ this.name())
}
object_literal1.greeting("Welcome")
I want to access the value of object literal's property(here fullName) inside the object literal's function(here greeting). But while doing so I am getting error. Please let me know where I am going wrong and how to do that?
|
|
|
|
|
Member 13954890 wrote: But while doing so I am getting error. What is the error?
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Same question as below with different wording. Which line errors and what error?
|
|
|
|
|
greeting : (message) => console.log(message + " "+ this.name())
^
TypeError: this.name is not a function
|
|
|
|
|
|
The "function" version works so just use it.
|
|
|
|
|
let person = {
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : function() {
return this.firstName + " " + this.lastName;
}
}
console.log(person.fullName())
When I am using arrow function here then I am getting undefined undefined as my output. Could anyone please let me know why this is happening. Below is my code with arrow function.
let person = {
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : () => {
return this.firstName + " " + this.lastName;
}
}
console.log(person.fullName())
|
|
|
|
|
Arrow functions do not have access to this. They are not meant to be used the way you are doing here.
JavaScript Arrow Function[^]
Quote: with arrow functions there are no binding of this.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
I am in the process of building a website in Squarespace, I am using Javascript to create a multi-lingual website in English and French. I differentiate between English and French using the URL/Slug
Example
www.websitename.com/en/home
or
www.websitename.com/fr/home
Everything is translating, almost. I am having issues with the footer translating.
Here are some images
https://i.stack.imgur.com/rLjn1.png[^]
https://i.stack.imgur.com/ruE24.png[^]
https://i.stack.imgur.com/Bz1cx.png[^]
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/2.6.0/css/flag-icon.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(function() {
var defaultLanguage = 'en';
var lang = location.pathname.split("/")[1];
var defaultClass = 'lang-'+defaultLanguage+'';
var itemParent = "nav [class*='collection'],nav [class*='folder'],nav [class*='index'],nav [class*='group']";
if (lang == "" || lang.length > 2 ){
var lang = defaultLanguage;
}
$('a[href="/"]').addClass('lang-'+defaultLanguage+'').parents(itemParent).addClass('lang-'+defaultLanguage+'');
$('nav a:link:not([href^="http://"]):not([href^="https://"])').each(function () {
var langType = $(this).attr('href').split("/")[1];
var multiLanguageClass = 'multilanguage lang-' + langType + '';
if (undefined !== langType && langType.length <= 2)
$(this).addClass(multiLanguageClass).parents(itemParent).addClass(multiLanguageClass);
});
$('nav button').each(function () {
var langTypeFolder = $(this).attr('data-controller-folder-toggle').split("/")[0];
var multiLanguageClass = 'multilanguage lang-' + langTypeFolder + '';
if (undefined !== langTypeFolder && langTypeFolder.length <= 2)
$(this).addClass(multiLanguageClass);
});
if (lang == "fr") {
$('a[href="/"]').attr("href", "/fr/home/");
}
$('.exclude-me,.exclude-me a').addClass('exclude');
$('.sqs-svg-icon--list a,.SocialLinks-link').addClass('exclude');
$('.multilanguage:not(".lang-'+lang+',.exclude")').remove();
$('body').prepend('<div class="language"><a href="/en/home" class="lang-en"></a> <a href="/fr/home/" class="lang-fr"></a></div>');
});
</script>
[JavaScript] MULTI-LANGUAGE Javscript for Website - Pastebin.com[^]
|
|
|
|
|
Just debug your code and figure out what you're doing wrong. Should be pretty simple.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|