How to assign a value to a <span> within a magnificpopup window? - magnific-popup

I can access current .html() value of a span contained in a magnificPopup.
But I can not set this value.
This is what I mean:
parseAjax: function(mfpResponse) {
// This works perfectly
var mycontent = $(mfpResponse.data).find('#textreported').html();
// But this does not work
$(mfpResponse.data).find('#textreported').html('Text to be assigned');
}
Does anyone know what I'm doing wrong?
Thanks in advance.

I'll answer myself. This is the right way to do it:
parseAjax: function (mfpResponse) {
str = jQuery.parseHTML(mfpResponse.data)
$(str).find('#textreported').html('Text to be assigned');
mfpResponse.data = $(str)
}
It may be useful to someone.

Related

Push method in useState hook || REACT NATIVE

I have an array of items in a state variable like this.
const [items, setItems] = useState(["item1", "item2", "item3")])
How to replace one item in the array. Below is the method I have used to get it done.
{
let dummy = [...items]
dummy[1] = "items 1.1"
setItems(dummy)
}
But, I am thinking that this is not at all the right way to do this.
Is there any other simplified way to solve this? Thanks in Advance
Your solution is not wrong, but I would add an extra check to make sure that items array contains an element which you wish to change.
let dummy = [...items]
if(typeof dummy[1] == 'undefined') {
// does not exist
}
else {
// does exist
dummy[1] = "items 1.1"
}
setItems(dummy)
Or you can use slice
const idxToChange = 1
setItems([items.slice(0, idxToChange), "items 1.1", items.slice(idxToChange+1, items.length)])
A good explanation of slice
https://www.w3schools.com/jsref/jsref_slice_array.asp
Heres another way to do it. I don't know it's cleaner for you or not.
setItems(items=> items.map((item,idx)=> idx===1?"items 1.1":item));

How can I get string value of selector?

I mean when we initialize Selector like this:
let stringLocator = 'some element locator'
selector = new Selector(stringLocator)
is that possible to get original string locator somehow like this:
selector.locator
p.s. This question is related to this one where I've found some hacky workarounds to get testcafe display my xpath locators in error.
Testcafe does not support this, but you can use the following approach
function createSelector (locator) {
return Object.assign(Selector(locator), { locator });
}
const selector = createSelector('#button');
console.log(selector.locator)
I had the same issue yesterday. The apiFnChain contains the fnChain you used for the selector. It is behind a symbol. This is what helped me. Maybe this will help you too.
const selector = Selector('button.explore-button').withText('Explore the site')
const selectorFnChain = selector[Object.getOwnPropertySymbols(selector)[0]].options.apiFnChain
console.log(selectorFnChain)
This will give you this:
Selector('button.explore-button'),.withText('Explore the site')
You don't have to get the entire chain but this was the most helpful for me.

KoLite asyncCommand accessing element data

So I'm displaying a observable array in my view, and I want to be able to remove an element from that list using asyncCommand. However, I'm not sure how I should be getting that element. Is there a way of accessing or passing the selected element into the asyncCommand method?
Thanks for the input
addGroupCmd = ko.asyncCommand({
execute: function (data, complete) {
//access your observable here with the data object
//EX. var demo = data.id();
},
canExecute: function (isExecuting) {
return !isExecuting && isEditing();
}
}),
Ok, so I figured it out with it little bit of google's help. All you have to do is pass in the data parameter and ko.lite will figure out what object your talking about. pretty nice, not really sure how it works, but it does.

Xcode BOOL type: from input YES, I want to get value NO

I have a very simple method, but it does not work. Ultimately, from input YES, I want to get NO and reverse.
-(void)myMethod:(BOOL)ys{
if (ys==YES) {
myLabel.hidden=NO;
myButton.hidden=NO;
}{
myLabel.hidden=YES;
myButton.hidden=YES;
}
}
Can you guys help me to correct and shorten the code? Thanks
Maybe this is a litle easier:
-(void)myMethod:(BOOL)ys{
myLabel.hidden = !ys;
myButton.hidden = !ys;
}
-(void)myMethod:(BOOL)visible
{
[myLabel setHidden:!visible];
[myButton setHidden:!visible];
}
The code should be working. However, your code is not working is probably because you did not set the referencing outlets for your label and button (If you created them with interface builder).
Referencing outlets should be set like this. Otherwise, the complier would not know if the button you want to hide is the button on the interface.
If you created the button/label with codes, check if you have them released before you are trying to set them visible or not please.
-(void)myMethod:(BOOL)ys{
if (ys) {
myLabel.hidden=NO;
myButton.hidden=NO;
} else {
myLabel.hidden=YES;
myButton.hidden=YES;
}
}
If we are trying to make it short...`
-(void)myMethod:(BOOL)ys{
myLabel.hidden = myButton.hidden = !ys;
}

dojo - programmatic way to show invalid message

dojo newbie - giving it a shot.
After submitting a form, If an error is returned from the server I would like to show that message on the dijit.form.ValidationTextBox
var user_email = dijit.byId("login_user_email");
user_email.set("invalidMessage", data["result"]["user_email"]);
//need to force show the tooltip but how???
Any help much appreciated.
See it in action at jsFiddle.
Just show tooltip:
var textBox = bijit.byId("validationTextBox");
dijit.showTooltip(
textBox.get("invalidMessage"),
textBox.domNode,
textBox.get("tooltipPosition"),
!textBox.isLeftToRight()
);
Temporarily switch textBox validator, force validation, restore the original validator:
var originalValidator = textBox.validator;
textBox.validator = function() {return false;}
textBox.validate();
textBox.validator = originalValidator;
Or do both at once.
I think you can show the tooltip via myVTB.displayMessage('this is coming from back end validation'); method
you need to do the validation in the validator-method. like here http://docs.dojocampus.org/dijit/form/ValidationTextBox-tricks
you also need to focus the widget to show up the message! dijit.byId("whatever").focus()
#arber solution is the best when using the new dojo. Just remember to set the focus to the TextBox before calling the "displayMessage" method.
I am using dojo 1.10 which works create as follows:
function showCustomMessage(textBox, message){
textBox.focus();
textBox.set("state", "Error");
textBox.displayMessage(message);
}
Dojo reference guid for ValidationTextBox: https://dojotoolkit.org/reference-guide/1.10/dijit/form/ValidationTextBox.html
I know this question is ancient, but hopefully this'll help someone. Yes, you should use validators, but if you have a reason not to, this will display the message and invalidate the field:
function(textbox, state /*"Error", "Incomplete", ""*/, message) {
textbox.focus();
textbox.set("state", state);
textbox.set("message", message);
}
You can call directly the "private" function:
textBox._set('state', 'Error');
You get the same result as #phusick suggested but with less code and arguably in a more direct and clean way.
Notes:
_set is available to ValidationTextBox as declared on its base class dijit/_WidgetBase.
Live demo:
http://jsfiddle.net/gibbok/kas7aopq/
dojo.require("dijit.form.Button");
dojo.require("dijit.form.ValidationTextBox");
dojo.require("dijit.Tooltip");
dojo.ready(function() {
var textBox = dijit.byId("validationTextBox");
dojo.connect(dijit.byId("tooltipBtn"), "onClick", function() {
dijit.showTooltip(
textBox.get('invalidMessage'),
textBox.domNode,
textBox.get('tooltipPosition'), !textBox.isLeftToRight()
);
});
dojo.connect(dijit.byId("validatorBtn"), "onClick", function() {
// call the internal function which set the widget as in error state
textBox._set('state', 'Error');
/*
code not necessary
var originalValidator = textBox.validator;
textBox.validator = function() {return false;}
textBox.validate();
textBox.validator = originalValidator;
*/
});
});