add validation when we enter wrong phone number using intl-tel-input angular 4 - angular2-routing

I am using intl-tel-input angular 4 for validate phone number ,when I added this its showing country code with phone number but if enter wrong phone its not showing error message. For this I am using this code :-
<ngx-intl-tel-input name="phone" id ="phone" [(value)]="model.phone" required="required" [preferredCountries]="preferredCountries" ></ngx-intl-tel-input>
this is my html file code and here my component.ts file code :-
$("#phone").intlTelInput({
utilsScript: "../../build/js/utils.js"
});
when I am added this it showing error message:-
"core.es5.js:1084 ERROR Error: Uncaught (in promise): TypeError: $(...).intlTelInput is not a function"
for this I am tried this code but no luck :-
https://jsbin.com/yacokiyece/edit?html,css,js,output
this is git code which I follow :-
https://github.com/webcat12345/ngx-intl-tel-input

You'll need to add the code below in your default-country-ip.js file.
$("#phone").intlTelInput({
initialCountry: "auto",
geoIpLookup: function(callback) {
$.get('//ipinfo.io', function() {}, "jsonp").always(function(resp) {
var countryCode = (resp && resp.country) ? resp.country : "";
callback(countryCode);
});
},
utilsScript: "js/utils.js" // just for formatting/placeholders etc
});
var telInput = $("#phone"),
errorMsg = $("#error-msg"),
validMsg = $("#valid-msg");
// initialise plugin
telInput.intlTelInput({
utilsScript: "js/utils.js"
});
var reset = function() {
telInput.removeClass("error");
errorMsg.addClass("hide");
validMsg.addClass("hide");
};
// on blur: validate
telInput.blur(function() {
reset();
if ($.trim(telInput.val())) {
if (telInput.intlTelInput("isValidNumber")) {
validMsg.removeClass("hide");
} else {
telInput.addClass("error");
errorMsg.removeClass("hide");
}
}
});
// on keyup / change flag: reset
telInput.on("keyup change", reset);
Check out this repo for a much detailed guide

Related

Fullcalendar using resources as a function with select menu

Using Fullcalendar 4, I am trying to show/hide my resources using a select menu. When the user selects one of the providers from a menu, I want to only show that one resourc's events.
Above my fullcalendar I have my select menu:
<select id="toggle_providers_calendar" class="form-control" >
<option value="1" selected>Screech Powers</option>
<option value="2">Slater</option>
</select>
I am gathering the resources I need using an ajax call on my included fullcalendar.php page. I am storing them in an object and then trying to control which resources are shown onscreen:
document.addEventListener('DOMContentLoaded', function() {
var resourceData = [];
$.getJSON('ajax_get_json.php?what=schedule_providers_at_location',
function(data) {
$.each(data, function(index) {
resourceData.push({
id: data[index].value,
title: data[index].text
});
});
console.log(resourceData);
});
//below, set the visible resources to whatever is selected in the menu
//using 1 in order for that to show at start
var visibleResourceIds = ["1"];
//below, get the selected id when the the menu is changed and use that in the toggle resource function
$('#toggle_providers_calendar').change(function() {
toggleResource($('#toggle_providers_calendar').val());
});
var calendar_full = document.getElementById('calendar_full');
var calendar = new FullCalendar.Calendar(calendar_full, {
events: {
url: 'ajax_get_json.php?what=location_appointments'
},
height: 700,
resources: function(fetchInfo, successCallback, failureCallback) {
// below, I am trying to filter resources by whether their id is in visibleResourceIds.
var filteredResources = [];
filteredResources = resourceData.filter(function(x) {
return visibleResourceIds.indexOf(x.id) !== -1;
});
successCallback(filteredResources);
},
...
});
// below, my toggle_providers_calendar will trigger this function. Feed it resourceId.
function toggleResource(resourceId) {
var index = visibleResourceIds.indexOf(resourceId);
if (index !== -1) {
visibleResourceIds.splice(index, 1);
} else {
visibleResourceIds.push(resourceId);
}
calendar.refetchResources();
}
To make sure the getJSON is working, I have console.log(resourceData). The information in the console once it's gathered is:
[{id: '1', title: 'Screech Powers'}, {id: '2', title: 'Slater}]
... the above are the correct resources that can be chosen/rendered. So that seems to be okay.
On page load, no resources show at all, when resource id of '1' (Screech Powers) should be shown per my code. Well, at least, that's what I am trying to do right now.
When the menu changes, resources will show/hide, but not based on what's selected; the logic of only showing what is selected in the menu doesn't seem to be working.
I used to use a URL request for my resources: 'ajax_get_json.php?what=schedule_providers_at_location', and it worked fine! All resources show then their events properly. I am just trying to modify it by using a menu to show/hide the resources as needed.
Here's what I'm doing to make it happen so far! In case someone comes across this post ever, this will help.
Here's my code before my fullcalendar code.
var resourceData = [];
var visibleResourceIds = [];
$.getJSON('ajax_get_json.php?what=schedule_providers_at_location',
function(data) {
$.each(data, function(index) {
resourceData.push({
id: data[index].value,
title: data[index].text
});
});
});
$('#toggle_providers_calendar').change(function() {
toggleResource($('#toggle_providers_calendar').val());
});
My select menu with id 'toggle_providers_calendar' is the same as my original post. My fullcalendar resources as a function is the same too.
After the calendar is rendered, here are the changes I made to my toggle resources function:
// menu button/dropdown will trigger this function. Feed it resourceId.
function toggleResource(resourceId) {
visibleResourceIds = [];
//if select all... see if undefined from loading on initial load = true
if ((resourceId == '') || (resourceId === undefined)) {
$.map( resourceData, function( value, index ) {
visibleResourceIds.push(value.id);
});
}
var index = visibleResourceIds.indexOf(resourceId);
if (index !== -1) {
visibleResourceIds.splice(index, 1);
} else {
visibleResourceIds.push(resourceId);
}
calendar.refetchResources();
}
This causes the resources to show and hide properly. If the user selects "Show All" that works too!
In order to have a default resource show on load, I add this to my fullcalendar script:
loading: function(bool) {
if (bool) {
//insert code if still loading
$('.loader').show();
} else {
$('.loader').hide();
if (initial_load) {
initial_load = false;
//code here once done loading and initial_load = true
var default_resource_to_show = "<?php echo $default_provider; ?>";
if (default_resource_to_show) {
//set the menu to that provider and trigger the change event to toggleresrource()
$('#toggle_providers_calendar').val(default_provider).change();
} else {
//pass in nothing meaning 'select all' providers for scheduler to see
toggleResource();
}
}
}
},
I am using a bool variable of initial_load to see if the page was just loaded (basically not loading data without a page refresh). The bool of initial_load = true is set outside of DOMContentLoaded
<script>
//show selected date in title box
var initial_load = true;
document.addEventListener('DOMContentLoaded', function() {
My only current problem is that when toggleResource function is called, the all day vertical time block boundaries don't line up with the rest of the scheduler. Once I start navigating, they do, but I don't understand why it looks like this on initial load or when toggleResource() is called:
Any thoughts on how to correct the alignment of the allday vertical blocks?

Integrate MPGS session.js in Aurelia SPA

I am trying to integrate the MasterCard Payment Gateway services to a SPA using Aurelia.
I am trying to use the hosted checkout mechanism to integrate MPGS.
I am writing code in the attached event of the Aurelia viewmodel to load the session.js library and on load of the library adding another script element to initialize the session.
The attached method is listed below.
this.mpgsSessionScript = `if (self === top) { var antiClickjack = document.getElementById("antiClickjack"); antiClickjack.parentNode.removeChild(antiClickjack); } else { top.location = self.location; } PaymentSession.configure({ fields: { card: { number: "#card-number", securityCode: "#card-cvv", expiryMonth: "#card-expiry-month", expiryYear: "#card-expiry-year" } }, frameEmbeddingMitigation: ["javascript"], callbacks: { initialized: function(response) { console.log(response); }, formSessionUpdate: function(response) { } } }); function pay() { PaymentSession.updateSessionFromForm('card'); }`;
this.styleElement = document.createElement('style');
this.styleElement.setAttribute('id', "antiClickjack");
this.styleElement.innerText = "body{display:none !important;}";
document.head.appendChild(this.styleElement);
this.scriptElement = document.createElement('script');
this.scriptElement.src = this.sessionJs;
this.scriptElement.onload = () => {
const innerScriptElement = document.createElement('script');
innerScriptElement.innerText = this.mpgsSessionScript;
document.body.appendChild(innerScriptElement);
};
document.body.appendChild(this.scriptElement);
I can successfully run the code the and the script elements are added to DOM and also, the antiClickjack style gets removed, which indicates that the script element gets added.
But the issue is, the card number and the cvv elements are not getting enabled for input. If successfully initialized, the card number and the cvv elements should get enabled.
I do not see any errors in the console. Any help would be appreciated.

Displaying a report with JS: How to check if a report exist?

Is there a convenient was to check if a report with the given report name exists using JavaScript?
Following this official guide on how to display a report I managed to display a report with the name given in the URL. If the given report name does not match a report I get a error:
Could not open successfully the report 'fake-name' (The report '/shared/fake-name.icc-report (null)' does not exists.)
So I want to redirect the user if the report does not exists and for that I need something like a function that gives me true or false based on the report name.
Is there any way this can be done?
Thanks. :)
I suggest using these options to have access to openReport callback:
var options = {
root: ic3root,
rootLocal: ic3rootLocal,
imagesPath: 'images',
//librariesMode:'dev',
callback: function () {
$('#intro').remove();
var ic3reporting = new ic3.Reporting(
{
noticesLevel: ic3.NoticeLevel.ERROR,
dsSettings: {
url: "http://<your_domain>/icCube/gvi"
}
});
ic3reporting.setupGVIConfiguration(function () {
ic3reporting.setupApplication(
{
mode: ic3.MainReportMode.REPORTING,
hideTopPanel: true,
noticesLevel: ic3.NoticeLevel.ERROR,
container: $("#container")
});
ic3reporting.openReport({
report: {
name: 'shared/report23'
}
}, function (reportState) {
var reportExists = _.isEmpty(ic3reporting.reportName());
})
});
}
};
ic3ready(options);
You may want to redirect user in case "reportExists" equals to false

Cannot insert JavaScript variable into Jade

I'm trying to insert a normal JavaScript expression into a Jade file. But my app keep getting error message when I add isAccepted variable into my code.This is the error message.
Your app is crashing. Here's the latest log.
Errors prevented startup:
While building the application:
jade-test.jade: Jade syntax error: Expected identifier, number, string, >boolean, or null
{{isAccepted ? 'class1' : 'class2...
^
packages/compileJade/plugin/handler.js:44:1: Cannot read property 'head' >of undefined (compiling jade-test.jade) (at fileModeHandler)
Your application has errors. Waiting for file change.
This is my code:
jade-test.jade
template(name="layout")
h1 This is layout template
h2 This is h2 paragraph
h3 This is h3 paragraph
+hello
template(name="hello")
h4 This is home template
button Click me
p You have click me #{counter} times.
- var isAccepted = true
button(class=isAccepted ? 'class1' : 'class2') I'm the right choice.
jade-test.js
if (Meteor.isClient) {
// counter starts at 0
Session.setDefault('counter', 0);
Template.hello.helpers({
counter: function () {
return Session.get('counter');
}
});
Template.hello.events({
'click button': function () {
// increment the counter when button is clicked
Session.set('counter', Session.get('counter') + 1);
}
});
Router.route('/', function() {
this.render('layout');
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
Not sure if inserting javascript code like this in jade is supported, you should probably use a helper instead.
I don't think the ternary expression syntax is valid too, again, use a helper.
JADE
template(name="hello")
h4 This is home template
button Click me
p You have click me #{counter} times.
button(class=isAccepted) I'm the right choice.
JS
Template.hello.helpers({
isAccepted: function(){
var isAccepted = true;
return isAccepted ? "class1" : "class2";
}
});

Facebook FriendsList window not opening in Internet Explorer 8

I'm using the FB.UI() JavaScript SDK to get the selected friends id, when the user selects friends from Friendslist request dialog window.
The selected friends id is passed to a handler file.
The above situation is working fine in Firefox, that is, I am able to get the friends Id, but the same is not working in Internet Explorer 8.
In IE8, I am getting the error below when I click the button to open the friends request dialog.
API Error Code: 191 API Error Description: The specified URL is not
owned by the application Error Message: redirect_uri is not owned by
the application.
I had given the redirect_uri also but I'm not getting the friends id.
The code is given below:
function sendRequestToManyRecipients() {
alert("sendRequestToManyRecipients");
FB.ui({method: 'apprequests',
appId : '',
display: 'popup',
message: 'My Group'
}, requestCallback);
}
function requestCallback(response) {
getMultipleRequests(response.request_ids);
}
var friend=new Array();
var sfriend="";
function getMultipleRequests(request_ids)
{
if (response && request_ids)
{
var ids = request_ids;
var _batch = [];
for (var i = 0; i < ids.length; i++)
{
_batch.push({ "method": "get", "relative_url":ids[i] });
}
if (_batch.length > 0)
{
FB.api('/', 'POST', { batch: _batch }, function (res)
{
for (var j = 0; j < res.length; j++)
{
body = res[j].body;
var myObject = eval('(' + body + ')');
friendID = myObject.to.id;
friend[j]=friendID.toString();
}
});
}
}
showfriends();
}
function showfriends()
{
for (var i = 0; i < friend.length; i++)
{
sfriend=sfriend+","+friend[i].toString();
}
if(sfriend != null)
{
window.open("Friends.ashx?id="+sfriend,'WinName','width=900,height=500,left=200,top=200'); }
}
I'm searching for a solution but I am not able to find the correct one.
Does anyone have a solution to this?
Are you want to get the friend id that the user have sent in the apprequest dialog?
Consider using request 2.0 efficient, which can help you get the ids without calling another api after sending the request
I have answered a similar question before, please take a look:
how to get user id on facebook request dialog
updated: 2011-11-29
For your ref, I use this code before for a project on fb app, which works on both IE8, Firefox 7, chrome 15
FB.ui({
method : "apprequests",
title : "title",
message : "messafe!!",
display : "iframe"
},
inviteCallback
);
function inviteCallback(response) {
// Requests 2.0 Efficient
// {
// request: ‘request_id’
// to:[array of user_ids]
// }
if (response.request) {
var receiverIDs = response.to;
document.inviteForm.receivers.value = receiverIDs.join(",");
document.inviteForm.submit();
}
}

Resources