I have a custom element (a partial URL) called #customElement('partialurl')
partialurl.js
get isValid(){
if (this.element === undefined || this.element === null){
return false;
}
else{
const partialUrl = new RegExp('^\/[a-z0-9]+([-\/](?:[a-z0-9]+))*(\.(?:jpeg|jpg|gif|png|htm|html|asp|xml|txt|pdf))?$');
if (partialUrl.test(this.element)) {
return true;
} else {
return false;
}
}
}
My question is how do I reference the 'isValid'?
For example - this file references the custom element
html
<partialurl disabled.bind="readonly" value.bind="baseContent.LinkDestination" />
js
bind(){
return this.dataContext.getContent(this.id)
.then(baseContent => {
this.baseContent = baseContent;
this.validator = this.validation.on(this)
.ensure('baseContent.LinkDestination').isValidFromCustomElement();
}); }
I know the above doesn't work, I am new to Aurelia and still finding my feet with it.
Related
i have this method that returns an object. if i run the code below i find that the second console.log() hits first and the object returns undefined
private routeAndPassengerDataObject: undefined | RouteAndPassenger;
public getDataFromRouteAndPassengerObject(fileName?: string): RouteAndPassenger {
if (this.routeAndPassengerDataObject) {
return this.routeAndPassengerDataObject;
}
if (typeof fileName !== 'string') {
throw new Error(`${fileName} has to be a string`);
}
cy.fixture(fileName).then((data: unknown) => {
if (!isValidRouteAndPassengerObject(data)) {
throw new Error(`${data} is not valid`);
}
console.log(`this is first`);
this.routeAndPassengerDataObject = data;
});
console.log(`this is second`);
return this.routeAndPassengerDataObject!;
}
}
const routeAndPassengerData = getDataFromRouteAndPassengerObject()
console.log(routeAndPassengerData);
result-
this is second
this is first
undefined
would like to know how to handle this please.
returing the object as cypress.chainable like below has worked for me-
public getDataFromRouteAndPassengerObject(fileName?: string): Cypress.Chainable<RouteAndPassenger> {
if (this.routeAndPassengerDataObject) {
return cy.wrap(this.routeAndPassengerDataObject);
}
if (typeof fileName !== 'string') {
throw new Error(`${fileName} has to be a string`);
}
return cy.fixture(fileName).then((data: unknown) => {
if (!isValidRouteAndPassengerObject(data)) {
throw new Error(`${data} is not valid`);
}
console.log(`this is first`);
this.routeAndPassengerDataObject = data;
return cy.wrap(this._routeAndPassengerDataObject);
});
}
and then calling the object like so-
const routeAndPassengerData = getDataFromRouteAndPassengerObject().then((routeAndPassenger)=>{
console.log(routeAndPassenger)
})
I'm trying to make a follow and unfollow techniques to user profile
I made this code but the main problem is that the user followed successfully but if you tap the button again the toast will show that unfollowed and the button image will change (like you will follow again) but if you refresh the following image show again it's like nothing happen
switch (BtnFollow?.Tag?.ToString())
{
case "Add": //Sent follow
BtnFollow.SetColor(Color.ParseColor(AppSettings.MainColor));
BtnFollow.SetImageResource(Resource.Drawable.ic_tick);
BtnFollow.Tag = "friends";
DataUser.IsFollowing = true;
Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_Sent_successfully_followed),
ToastLength.Short)?.Show();
PollyController.RunRetryPolicyFunction(new List<Func<Task>> { () => RequestsAsync.User.FollowUnFollowUserAsync(UserId, true) });
break;
case "friends": //Sent un follow
BtnFollow.SetColor(Color.ParseColor("#444444"));
BtnFollow.SetImageResource(Resource.Drawable.ic_add);
BtnFollow.Tag = "Add";
DataUser.IsFollowing = false;
Toast.MakeText(Context, Context.GetText(Resource.String.Lbl_Sent_successfully_Unfollowed),
ToastLength.Short)?.Show();
PollyController.RunRetryPolicyFunction(new List<Func<Task>> { () => RequestsAsync.User.FollowUnFollowUserAsync(UserId, false) });
break;
}
var dataUser = GlobalContext?.MainFragment?.ArtistsAdapter?.ArtistsList?.FirstOrDefault(a => a.Id == DataUser.Id);
if (dataUser != null)
{
dataUser.IsFollowing = DataUser.IsFollowing;
GlobalContext.MainFragment.ArtistsAdapter.NotifyDataSetChanged();
}
}
catch (Exception exception)
{
Methods.DisplayReportResultTrack(exception);
}
}
and this code to check the following status
if (DataUser.IsFollowing != null && DataUser.IsFollowing.Value) // My Friend
{
BtnFollow.SetColor(Color.ParseColor(AppSettings.MainColor));
BtnFollow.SetImageResource(Resource.Drawable.ic_tick);
BtnFollow.Tag = "friends";
}
else //Not Friend
{
BtnFollow.SetColor(Color.ParseColor("#444444"));
BtnFollow.SetImageResource(Resource.Drawable.ic_add);
BtnFollow.Tag = "Add";
}
}
I'm using CoreUI admin template with vue js.
I want to custom date range inside datable componen.
Can anyone help me to configure out with this problem?
Anyways, I have found plugin for date range in dataTable
$.fn.dataTable.ext.search.push(function(oSettings, aData, iDataIndex) {
if (typeof aData._date == "undefined") {
aData._date = new Date(aData[0]).getTime();
}
if (minDateFilter && !isNaN(minDateFilter)) {
if (aData._date < minDateFilter) {
return false;
}
}
if (maxDateFilter && !isNaN(maxDateFilter)) {
if (aData._date > maxDateFilter) {
return false;
}
}
return true;
});
There is an example of CDataTable with a date range in the docs:
https://coreui.io/vue/docs/components/table.html#custom-data-structures-and-filtering-sorting
I upgrade my Jasmine 1.3 to 2.0 so I added a custom matcher to check css is present.Below is the code to check the matcher
hasClass = function(actual,expected){
return actual.getAttribute('class').then(function (classes) {
return classes.split(' ').indexOf(expected) !== -1;
});
}
But when I upgrade to Jasmine 2 then promise throws error by protactor as it expect return but below is async process
hasClass = function(){
return compare: function(actual,expected){
return actual.getAttribute('class').then(function (classes) {
return {pass: classes.split(' ').indexOf(expected) !== -1};
});
}
}
How can I test class is present in element I don't want to use jasmine-jquery??
The pass should be a promise, not resolved in one. Try to place this in your beforeEach:
this.addMatchers({
hasClass: function() {
return {
compare: function(actual, expected) {
return {
pass: actual.getAttribute('class').then(function(classes) {
return classes.split(' ').indexOf(expected) !== -1;
})
};
}
};
}
});
I have a view that is loaded with a blank viewmodel initially. I want to populate that already rendered view with a json object (obtained view ajax post) that was based off the viewmodel for that view.
Is there a way of automatically doing this?
Is there a way of doing it in reverse? (fields to matching viewmodel json object)
The only way I am aware of taking data return from an ajax call and putting it in a field is manually
$('#TextField1').val(result.TextField1);
etc..
to send it back to the controller you can do
data: $('form').serialize(),
this will take all of the fields in that form and send them back to the controller
Ok it looks like this will suit my needs.
I need to follow a convention of naming containers the same name as their respective properties as well as putting a class on them to indicate that they contain subfields.
function MapJsonObjectToForm(obj, $container) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var $field = $container.find('#' + key);
if ($field.is('div')) {
MapJsonObjectToForm(obj[key], $field);
} else {
if (obj[key] == null) {
if ($field.hasClass('select2-offscreen')) {
$field.select2('val', '');
$field.select2().trigger('change');
} else {
$field.val("");
}
} else {
if ($field.hasClass('select2-offscreen')) {
$field.select2('val', obj[key]);
$field.select2().trigger('change');
} else {
$field.val(obj[key]);
}
}
}
}
}
}
function MapFormToJsonObject(containerid) {
var obj = {};
$('.dataitem').each(function () {
var exclude = "s2id";
if ($(this).attr("ID").substring(0, exclude.length) !== exclude) {
var parents = $(this).parents(".has-sub-fields");
if (parents.length > 0) {
obj = FindParents(obj, parents.get(), $(this).attr("ID"), $(this).val());
} else {
obj[$(this).attr("ID")] = $(this).val();
}
}
});
return obj;
}
function FindParents(obj, arr, id, value) {
if (arr.length == 0) {
obj[id] = value;
return obj;
}
var parentID = $(arr[arr.length - 1]).attr("ID");
arr.pop();
if (obj[parentID] == null) {
obj[parentID] = {};
}
obj[parentID] = FindParents(obj[parentID], arr, id, value);
return obj;
}