CQ-Dialog page properties can not be stored from site admin but works from sidekick - aem

The purpose of the following function is to allow the user to save the edited page properties in the CQ-Dialog even though if they invalid by clicking on the button save anyway:
PageProperties.showMsg = function(dialog, config, errorMessage) {
CQ.Ext.MessageBox.buttonText.ok = "save anyway";
CQ.Ext.Msg.show({
title : "Completeness check failed",
msg : errorMessage,
buttons: CQ.Ext.Msg.OKCANCEL,
fn : function(buttons) {
if(buttons == "ok") {
dialog.form.items.each(function(field) {
// clear fields with emptyText so emptyText is not submitted
if (field.emptyText && field.el && field.el.dom && field.el.dom.value == field.emptyText) {
field.setRawValue("");
}
});
var action = new CQ.form.SlingSubmitAction(dialog.form, config);
dialog.form.isValid = function() {
return true;
};
dialog.form.doAction(action);
dialog[dialog.closeAction]();
CQ.Util.reload();
}
}
});
};
This functions works fine from the sidekick. When I click on save anyway all current values of the page properites are stored regardless if they are valid or not. This does not work from the site admin. when I call the page properties of the same page from the site admin and try to save the page properties with invalid values by clicking on save anyway, this does not works (old values are stored and nothing changes).
I hope somebody can help. thank you

I found the solution. the problem was the function CQ.Util.reload(). It prevent storing the values

Related

converse.js : How can I pre-populate the Username field in the login form

I have tried this:
<script>
converse.initialize({
websocket_url: 'wss://xxx.xxx.xxx/websocket',
jid:'xxxxx#xxxx.xxx.xxx',
show_controlbox_by_default: true,
view_mode: 'overlayed' });
</script>
I was hoping this would display a login form with the Username field already populated with the value given in jid. However converse.js still displays an empty field with the default placeholder.
I'm using "https://cdn.conversejs.org/4.0.1/dist/converse.min.js"
OK so I'm not a javascript programmer but the solution I've come up with is to modify the renderLoginPanel() function and add the following
renderLoginPanel() {
this.el.classList.add("logged-out");
if (_.isNil(this.loginpanel)) {
this.loginpanel = new _converse.LoginPanel({
'model': new _converse.LoginPanelModel()
});
const panes = this.el.querySelector('.controlbox-panes');
panes.innerHTML = '';
panes.appendChild(this.loginpanel.render().el);
this.insertBrandHeading();
} else {
this.loginpanel.render();
}
/* ***Add this line to pre-populate the username field*** */
document.getElementById("converse-login-jid").value = _converse.jid;
this.loginpanel.initPopovers();
return this;
},
I'd be interested to hear if this is anywhere near a good solution.

Click Anywhere Pop Up

I'm trying to create a popup (new window) that appears when a person clicks anywhere on the page , but the problem is that my script creates a new tab for every click . I created a blogspot account just for test : http://faqetest123.blogspot.al/
what should I do for that ?
(example of a site that is using the popup that im trying to create is :atdhe.so)
Here is my code :
<script type="text/javascript">
document.onclick=function()
{
window.open('http://www.facebook.com');
}
</script>
Thanks
The window.open() function returns a reference to that window. So you should be able to use that reference to navigate to a new URL at a later time. Something like this:
var myPopup;
document.onclick=function()
{
if (!myPopup) {
myPopup = window.open('http://www.facebook.com');
} else if (myPopup.closed) {
myPopup = window.open('http://www.google.com');
} else {
myPopup.location.href = 'http://www.stackoverflow.com';
}
}
Note that this also attempts to check if the user has closed the pop-up and re-opens it.
Edit: Based on your comments below, it looks like I misunderstood. In order to have the popup execute once and then not again, you can simply remove the event handler after processing it. Something like this:
document.onclick=function()
{
window.open('http://www.facebook.com');
document.onclick = null;
}

Dont want to allow manual tagging in bootstrap tokenfiled

I am using bootstrap-tokenfield http://sliptree.github.io/bootstrap-tokenfield/ with jquery autocomplete. I want tagging with autocomplete content(from dropdown only). When user is inputting something and hit enter key it automatically creates tags. I dont want to allow this feature to the users. Is there any option/flag to set it? Any help would be appreciated. Thanks in advance.
Using listener tokenfield:createtoken you can validate the token before creating it.
Info: http://sliptree.github.io/bootstrap-tokenfield/#events
$('#tokenfield').on('tokenfield:createtoken', function (event) {
var exists = false;
$.each(yourSource, function(index, value) {
if (event.attrs.value === value) {
exists = true;
}
});
if(!exists) {
event.preventDefault(); //prevents creation of token
}
});

How to recognise whether form is modified or not in extjs4

I am working in extjs4. I am having form with multiple textboxes,radio buttons and some more elements.Suppose i clicked on modify form. If user made some editing in form,then i want to display message box window in order to ask confirmation of saving of changes that user has made.If user closes form without any modifications,then that messagebox should not be appear.I was trying to use dirtychange event of form as-
me.getForm().on('dirtychange', function(form, isDirty) {
console.log(form.events);
if( isDirty ) {
isChanged=true;
}
else {
isChanged=false;
}
});
But its setting isChanged variable to always true though form is not modified.
So how to identify whether form is modified or not so that i can display confirmation message box.
You can use Ext.data.Model-property-dirty to determine if a record has been modified.
form.getRecord().dirty
If your record is dirty without you making any modifications, you can try this to find which field is dirty.
if (form.isDirty()) {
var fields = form.getForm().getFields().items;
for (var i=0; i<fields.length; i++) {
if (fields[i].isDirty()) {
if (Ext.isDefined(fields[i].name)) {
alert(fields[i].name);
}
}
}
}

How to fire place_changed event for Google places auto-complete on Enter key

The click seems to fire the event and set the cookies but pressing enter to submit doesn't set the cookies and instead the page redirects without the cookies.
function locationAuto() {
$('.search-location').focus(function () {
autocomplete = new google.maps.places.Autocomplete(this);
searchbox = this;
google.maps.event.addListener(autocomplete, 'place_changed', function () {
var thisplace = autocomplete.getPlace();
if (thisplace.geometry.location != null) {
$.cookie.raw = true;
$.cookie('location', searchbox.value, { expires: 1 });
$.cookie('geo', thisplace.geometry.location, { expires: 1 });
}
});
});
The .search-location is a class on multiple textboxes.
There is a submit button that takes the values from the cookies and redirects (server side)
Adapted from Jonathan Caulfield's answer:
$('.search-location').keypress(function(e) {
if (e.which == 13) {
google.maps.event.trigger(autocomplete, 'place_changed');
return false;
}
});
I've encountered this problem as well, and came up with a good solution. In my website I wanted to save the autocomplete.getPlace().formatted_address in a hidden input prior to submission. This worked as expected when clicking the form's submit button, but not when pressing the Enter key on the selection in the autocomplete's dropdown menu. My solution was as follows:
$(document).ready(function() {
// Empty the value on page load
$("#formattedAddress").val("");
// variable to indicate whether or not enter has been pressed on the input
var enterPressedInForm = false;
var input = document.getElementById("inputName");
var options = {
componentRestrictions: {country: 'uk'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
$("#formName").submit(function(e) {
// Only submit the form if information has been stored in our hidden input
return $("#formattedAddress").val().length > 0;
});
$("#inputName").bind("keypress", function(e) {
if(e.keyCode == 13) {
// Note that simply triggering the 'place_changed' event in here would not suffice, as this would just create an object with the name as typed in the input field, and no other information, as that has still not been retrieved at this point.
// We change this variable to indicate that enter has been pressed in our input field
enterPressedInForm = true;
}
});
// This event seems to fire twice when pressing enter on a search result. The first time getPlace() is undefined, and the next time it has the data. This is why the following logic has been added.
google.maps.event.addListener(autocomplete, 'place_changed', function () {
// If getPlace() is not undefined (so if it exists), store the formatted_address (or whatever data is relevant to you) in the hidden input.
if(autocomplete.getPlace() !== undefined) {
$("#formattedAddress").val(autocomplete.getPlace().formatted_address);
}
// If enter has been pressed, submit the form.
if(enterPressedInForm) {
$("#formName").submit();
}
});
});
This solution seems to work well.
Both of the above responses are good answers for the general question of firing a question when the user presses "enter." However - I ran into a more specific problem when using Google Places Autocomplete, which might have been part of the OP's problem. For the place_changed event to do anything useful, the user needs to have selected one of the autocomplete options. If you just trigger 'place_changed', the if () block is skipped and the cookie isn't set.
There's a very good answer to the second part of the question here:
https://stackoverflow.com/a/11703018/1314762
NOTE: amirnissim's answer, not the chosen answer, is the one to use for reasons you'll run into if you have more than one autocomplete input on the same page.
Maybe not the most user friendly solution but you could use JQuery to disable the enter key press.
Something like this...
$('.search-location').keypress(function(e) {
if (e.which == 13) {
return false;
}
});