selection range issue in IE9 - dom

I have the following JavaScript code works in IE6, IE7 and IE8. However, the parentElement() and commonParentElement() are not defined in IE9. Would anyone know how to workaround it?
if (document.selection)
{
var sel = document.selection;
var rng = sel.createRange();
if (rng)
{
if ("Control" == sel.type && typeof rng.commonParentElement != "undefined")
{
targetElement = rng.commonParentElement(); // undefined in IE9
}
else if (typeof rng.parentElement != "undefined")
{
targetElement = rng.parentElement(); // undefined in IE9
}
}
}

Related

Getting error as E/launcher - Error: TypeError: Cannot read property '0' of undefined

I'm getting below error while executing this code -
E/launcher - Error: TypeError: Cannot read property '0' of undefined
Need your help to resolve this issue in Protractor version 5.4.3
let objectLocator = function(){
var webElement = null;
//find locator using provided locator type and locator value
this.findLocator = function (locator, value) {
var locatorType = locator[0];
var locatorValue = locator[1];
if (typeof locatorType !== 'undefined') {
if (locatorValue.includes('#REPLACE#')) {
locatorValue = locatorValue.replace('#REPLACE#', value);
}
if (locatorType == 'id') {
if (locatorValue !== 'undefined') {
this.webElement = element(by.id(locatorValue));
}
} else if (locatorType == 'name') {
if (locatorValue !== 'undefined') {
this.webElement = element(by.name(locatorValue));
}
} else if (locatorType == 'xpath') {
if (locatorValue !== 'undefined') {
this.webElement = element(by.xpath(locatorValue));
}
} else if (locatorType == 'css') {
if (locatorValue !== 'undefined') {
this.webElement = element(by.css(locatorValue));
}
}
}
return this.webElement;
};
};
module.exports = new objectLocator();

Most suitable ionic component for linked inputs or a plugin

I'm building an app on ionic 3, and the UI proposal have this view to verify SMS.
Is any way to do this without using 4 different inputs and linking them with JS? a plugin or something?
Thanks in advance
Found a codepen that is similar
https://codepen.io/nirarazi/pen/ZGovQo
but the magic is in the js
$(function() {
'use strict';
var body = $('body');
function goToNextInput(e) {
var key = e.which,
t = $(e.target),
sib = t.next('input');
if (key != 9 && (key < 48 || key > 57)) {
e.preventDefault();
return false;
}
if (key === 9) {
return true;
}
if (!sib || !sib.length) {
sib = body.find('input').eq(0);
}
sib.select().focus();
}
function onKeyDown(e) {
var key = e.which;
if (key === 9 || (key >= 48 && key <= 57)) {
return true;
}
e.preventDefault();
return false;
}
function onFocus(e) {
$(e.target).select();
}
body.on('keyup', 'input', goToNextInput);
body.on('keydown', 'input', onKeyDown);
body.on('click', 'input', onFocus);
})

jsTree xml_data plugin not working in IE11

The jsTree xml_data plugin is not working in ie 11. It Works great in every browser (including ie10), but not in ie11. No error messages, only the "loading" forever.
$("#hierarquia").jstree({
"xml_data" : {"ajax" : {"url" : "XML.asp"}},
"plugins" : ["xml_data"]
});
Anyone have experienced this? I could not find any references for jsTree and ie11 on the web until now.
Thanks for any help!
In the the jstree.js file there is this function:
(function ($) {
$.vakata.xslt = function (xml, xsl, callback) {
var rs = "", xm, xs, processor, support;
// TODO: IE9 no XSLTProcessor, no document.recalc
if (window.ActiveXObject) {
var xslt = new ActiveXObject("Msxml2.XSLTemplate");
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
xmlDoc.loadXML(xml);
xslDoc.loadXML(xsl);
xslt.stylesheet = xslDoc;
var xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.transform();
callback.call(null, xslProc.output);
return true;
}
if(typeof window.DOMParser !== "undefined" && typeof window.XMLHttpRequest !== "undefined" && typeof window.XSLTProcessor === "undefined") {
xml = new DOMParser().parseFromString(xml, "text/xml");
xsl = new DOMParser().parseFromString(xsl, "text/xml");
// alert(xml.transformNode());
// callback.call(null, new XMLSerializer().serializeToString(rs));
}
if(typeof window.DOMParser !== "undefined" && typeof window.XMLHttpRequest !== "undefined" && typeof window.XSLTProcessor !== "undefined") {
processor = new XSLTProcessor();
support = $.isFunction(processor.transformDocument) ? (typeof window.XMLSerializer !== "undefined") : true;
if(!support) { return false; }
xml = new DOMParser().parseFromString(xml, "text/xml");
xsl = new DOMParser().parseFromString(xsl, "text/xml");
if($.isFunction(processor.transformDocument)) {
rs = document.implementation.createDocument("", "", null);
processor.transformDocument(xml, xsl, rs, null);
callback.call(null, new XMLSerializer().serializeToString(rs));
return true;
}
else {
processor.importStylesheet(xsl);
rs = processor.transformToFragment(xml, document);
callback.call(null, $("<div />").append(rs).html());
return true;
}
}
return false;
};
The if
if (window.ActiveXObject)
You need to add the following to it:
if (window.ActiveXObject || "ActiveXObject")
Hope that makes sense
EDIT:
Changed the if statement to the below, as earlier fix was causing problems on Chrome:
if (window.ActiveXObject !== undefined || "ActiveXObject" in window)

Do not submit empty form fields in ExtJS

I have an extjs form with fields. The user isn't required to enter data into each field so I do not want to submit the fields with no data. I want it to post only fields that actually have data. Is this possible?
I recommend using form's beforeaction event. While handling this event you can check all fields. If all values are empty just return false;. The following example works in ExtJS4 and has to work in ExtJS3:
myform.on('beforeaction', function(form, action) {
if (action.type == 'submit') {
var doSubmit = false, vals = form.getValues();
for (var i in vals)
if (vals[i] !== '') {
doSubmit = true;
break;
}
return doSubmit;
}
});
Actualy, the right way to not submit empty fields is to use action's submitEmptyText config. But it's not working in current version (ExtJS4.0.2a).
Another options is to override component's getSubmitValue() method and return null if this field is empty, this way it won't be included into submit fields.
{
xtype: 'combo',
getSubmitValue: function(){
var value = this.getValue();
if(Ext.isEmpty(value)) {
return null;
}
return value;
}
}
Instead of using form's submit, directly call Ext.Ajax.request(...) with the url, method type (GET/POST) and params (and any other options as explained in the call documentation).
To generate params, iterate over the form fields and check for null value before adding to params.
This bug is present in ExtJS 4.0.7 too.
As Molecule Man pointed:
Actualy, the right way to not submit empty fields is to use action's submitEmptyText config. But it's not working in current version (ExtJS4.0.2a).
A possible solution to fix this bug is by overriding 2 functions, getValues in "Ext.form.Basic" (where the bug is) and createForm (to create our basic form) in "Ext.form.Panel" by extension in the following way:
Ext.define("My.form.Basic", {
alias: "form.mybasic",
extend: "Ext.form.Basic",
getValues: function(asString, dirtyOnly, includeEmptyText, useDataValues) {
var values = {};
this.getFields().each(function(field) {
if (!dirtyOnly || field.isDirty()) {
var data = field[useDataValues ? "getModelData" : "getSubmitData"](includeEmptyText);
if (Ext.isObject(data)) {
var isArray = Ext.isArray;
Ext.iterate(data, function(name, val) {
if (includeEmptyText && val === "") {
val = field.emptyText || "";
}
if (includeEmptyText || ((!isArray(val) && val !== "") || (isArray(val) && val.length !== 0))) {
if (name in values) {
var bucket = values[name];
if (!isArray(bucket)) {
bucket = values[name] = [bucket];
}
if (isArray(val)) {
values[name] = bucket.concat(val);
}
else {
bucket.push(val);
}
}
else {
values[name] = val;
}
}
});
}
}
});
if (asString) {
values = Ext.Object.toQueryString(values);
}
return values;
}
});
Ext.define("My.form.Panel", {
alias: "form.mypanel",
extend: "Ext.form.Panel",
createForm: function() {
return Ext.create("My.form.Basic", this, Ext.applyIf({listeners: {}}, this.initialConfig));
}
});
The code is copied from the ext source code. The only change is inside the iteration of each field: introduced the following wrapping "if":
if (includeEmptyText || ((!isArray(val) && val !== "") || (isArray(val) && val.length !== 0)))
I am a bit late but, better later than never...

JScript error in XVal, Has anybody seen this error?

Microsoft JScript runtime error: 'this.Plugins[...]' is null or not an object
coming from this code:
var xVal = xVal || {
Plugins: {},
AttachValidator: function(elementPrefix, rulesConfig, pluginName) {
if (pluginName != null)
this.Plugins[pluginName].AttachValidator(elementPrefix, rulesConfig);
else
for (var key in this.Plugins) {
this.Plugins[key].AttachValidator(elementPrefix, rulesConfig);
return;
}
}
};
Make sure you are referencing xVal.AspNetNative.js AND xVal.jquery.validate.js in your master page.