ixxxl
(ixxxl)
January 21, 2022, 6:37am
1
Can i alert a user when he opens form in Internet Explorer? and close form, in fnot to continue editing.
I tried like this, but in explorer there is no alert..
fd.beforeCreate(function(vueConfig) {
console.log('beforeCreate started');
var browserName = (function (agent) {
switch (true) {
case agent.indexOf("edge") > -1: return "MS Edge";
case agent.indexOf("edg/") > -1: return "Edge (chromium based)";
case agent.indexOf("opr") > -1 && !!window.opr: return "Opera";
case agent.indexOf("chrome") > -1 && !!window.chrome: return "Chrome";
case agent.indexOf("trident") > -1: return "IE";
case agent.indexOf("firefox") > -1: return "Mozilla Firefox";
case agent.indexOf("safari") > -1: return "Safari";
default: return "other";
}
}) (window.navigator.userAgent.toLowerCase());
console.log('browser '+browserName);
if (browserName == 'IE') {
alert('Utilizati Chrome');
return fd.close();
}
});
Margo
(Margo)
January 21, 2022, 8:20am
2
Hello @ixxxl ,
Add the code within the spRendered function, it should work.
fd.spRendered(function() {
var browserName = (function (agent) {
switch (true) {
case agent.indexOf("edge") > -1: return "MS Edge";
case agent.indexOf("edg/") > -1: return "Edge (chromium based)";
case agent.indexOf("opr") > -1 && !!window.opr: return "Opera";
case agent.indexOf("chrome") > -1 && !!window.chrome: return "Chrome";
case agent.indexOf("trident") > -1: return "IE";
case agent.indexOf("firefox") > -1: return "Mozilla Firefox";
case agent.indexOf("safari") > -1: return "Safari";
default: return "other";
}
}) (window.navigator.userAgent.toLowerCase());
console.log('browser '+browserName);
if (browserName == 'IE') {
alert('Utilizati Chrome');
return fd.close();
}
});
1 Like
ixxxl
(ixxxl)
September 14, 2022, 12:11pm
4
@Margo
Good day!
strange but in some forms in explorer it doesn't work. in chrome show on console -browser chrome.
Console from explorer:
code in this form. this is a new form.
window.fd=fd
//var folder = [];
//var folderName = []
fd.spRendered(function() {
var browserName = (function (agent) {
switch (true) {
case agent.indexOf("edge") > -1: return "MS Edge";
case agent.indexOf("edg/") > -1: return "Edge (chromium based)";
case agent.indexOf("opr") > -1 && !!window.opr: return "Opera";
case agent.indexOf("chrome") > -1 && !!window.chrome: return "Chrome";
case agent.indexOf("trident") > -1: return "IE";
case agent.indexOf("firefox") > -1: return "Mozilla Firefox";
case agent.indexOf("safari") > -1: return "Safari";
default: return "other";
}
}) (window.navigator.userAgent.toLowerCase());
console.log('browser '+browserName);
if (browserName == 'IE') {
alert('Utilizati Chrome');
return fd.close();
}
});
fd.spRendered(function () {
function filterCategory(cat) {
//example filtering by one field
// var linieID = linie && linie.LookupId || linie || null;
var filter = '1';
fd.field('Sucursala').filter = "suc eq '" + filter + "'";
fd.field('Sucursala').widget.dataSource.read();
};
fd.field('Sucursala').ready().then(function() {
//filter Categories when form opens
filterCategory();
});
});
fd.spRendered(function () {
function listControl(){
fd.control('SPDataTable1').readonly=true
fd.field('Group').disabled = true
}
listControl();
});
fd.spRendered(function () {
function suc() {
fd.field('Cod_x0020_Sucursala').value = fd.field('Sucursala').value.Cod_x0020_Subdiviziune
if (!fd.field('Cod_x0020_Sucursala').value) {
fd.control('SPDataTable1').readonly = true
} else {
fd.control('SPDataTable1').readonly = false
}
}
fd.field('Sucursala').$on('change', suc)
});
fd.spRendered(function () {
function dep() {
const cod = fd.field('Cod_x0020_Sucursala').value
fd.field('Group').disabled = true
fd.field('Group').value = `S${cod}-RTL-Director;S${cod}-RTL-SpPrin;S${cod}-RTL-SefCasa;`
}
fd.field('Cod_x0020_Sucursala').$on('change', dep)
})
fd.spRendered(function (){
fd.control('SPDataTable1').ready().then(function (dt) {
//dt parameter is the same as fd.control('SPDataTable0')
console.log('SPDataTable7 is initialized');
//set width and height:
fd.control('SPDataTable1').dialogOptions = {
width: 1280,
height: 720
}
});
});
Margo
(Margo)
September 15, 2022, 8:49am
5
Hello @ixxxl ,
Did you test the same form in Chrome and Internet Explorer? Is that the complete code you have on the form?
There are errors in the console that can prevent code execution, and I can't match errors with the code that you shared.
ixxxl
(ixxxl)
September 15, 2022, 8:55am
6
@Margo
i test the same form in explorer and in chrome. it's all the code.
console from chrome: no errors. some of the code i think it's not suported in explorer, that's why i want to alert users , to use chrome or edge. but have 3 forms where this alert doesn't work. in 2 forms work well.
p.s .
here it works:
code from the form where it works
window.fd = fd;
fd.spRendered(function() {
var browserName = (function (agent) {
switch (true) {
case agent.indexOf("edge") > -1: return "MS Edge";
case agent.indexOf("edg/") > -1: return "Edge (chromium based)";
case agent.indexOf("opr") > -1 && !!window.opr: return "Opera";
case agent.indexOf("chrome") > -1 && !!window.chrome: return "Chrome";
case agent.indexOf("trident") > -1: return "IE";
case agent.indexOf("firefox") > -1: return "Mozilla Firefox";
case agent.indexOf("safari") > -1: return "Safari";
default: return "other";
}
}) (window.navigator.userAgent.toLowerCase());
console.log('browser '+browserName);
if (browserName == 'IE') {
alert('Utilizati Chrome sau EDGE');
return fd.close();
}
});
// Set fields propreties
fd.spRendered(function () {
//get all buttons
function setFieldPropreties() {
//Disable Sharepoint Save field
fd.toolbar.buttons[0].style = "display: none;";
fd.toolbar.buttons[1].text = "Închide";
//fd.field('Nume_x0020_prenume').value = _spPageContextInfo.userEmail;
// fd.field('Nume_x0020_prenume').value = _spPageContextInfo.userDisplayName;
// fd.field('Nume_x0020_prenume').disabled=true
fd.field('Nume_x0020_prenume').ready().then(function (field) {
field.disabled = true;
field.value=_spPageContextInfo.userDisplayName;
});
// _spPageContextInfo.userLoginName;
//Hide system fields
$('.hide').hide();
$('.sysfields').hide();
// Disable edit la cimpurile populate
// fd.field('Nume_x0020_prenume').value = null;
fd.field('Nume_x0020_prenume').required = true;
fd.field('Starea_x0020_cererii').disabled = true;
fd.field('Sector').disabled = true;
/* if (_spPageContextInfo.userDisplayName==="DDS.Priv.IBarbulat"){
$('.notif').show(); }
else{
$('.notif').hide(); } */
fd.field('Subdiviziunea').disabled = true;
fd.field('Func_x021b_ia').disabled = true;
fd.field('Boss_x0020_Level_x0020_1').disabled = true;
fd.field('Boss_x0020_Level_x0020_2').disabled = true;
fd.field('Boss_x0020_Level_x0020_3').disabled = true;
fd.field('Notificare').disabled = true;
fd.field('Num_x0103_r_x0020_de_x0020_tabel').disabled = true;
// fd.field('Title').value = "Cerere de concediu NR" + fd.field('ID').value
}
// executes setFieldPropreties on form load
setFieldPropreties();
});
fd.spRendered(function () {
function updateUserInfo2() {
pnp.sp.profiles.myProperties.get().then(function (result) {
var props = result.UserProfileProperties;
var sec = "";
var niv1 = "";
var niv2 = "";
var niv3 = "";
var tip = "";
var subdiv
for (var i = 0; i < props.length; i++) {
switch (props[i].Key) {
case 'DENNIVEL1':
//Form Field Internal name
niv1 = props[i].Value;
break;
case 'DENNIVEL2':
//Form Field Internal name
niv2 = props[i].Value;
break;
case 'DENNIVEL3':
//Form Field Internal name
niv3 = props[i].Value;
break;
// Sharepoint or AD attribute
case 'SECTORFUNCTIE':
//Form Field Internal name
sec = props[i].Value;
break;
case 'TIPSUBUNITATE':
//Form Field Internal name
tip = props[i].Value;
break;
case 'Office':
//Form Field Internal name
fd.field('Num_x0103_r_x0020_de_x0020_tabel').value = props[i].Value;
break;
// Sharepoint or AD attribute
case 'DEP':
//Form Field Internal name
fd.field('Subdiviziunea').value = props[i].Value;
break;
case 'Title':
//Form Field Internal name
fd.field('Func_x021b_ia').value = props[i].Value;
break;
case 'bossLevel1':
//Form Field Internal name
fd.field('Boss_x0020_Level_x0020_1').value = props[i].Value;
break;
case 'bossLevel2':
//Form Field Internal name
fd.field('Boss_x0020_Level_x0020_2').value = props[i].Value;
break;
case 'bossLevel3':
//Form Field Internal name
fd.field('Boss_x0020_Level_x0020_3').value = props[i].Value;
break;
case 'codSubdiviziune':
//Form Field Internal name
fd.field('Cod_x0020_Subdiviziune').value = props[i].Value;
break;
case 'NOTIFICARE':
//Form Field Internal name
fd.field('Notificare').value = props[i].Value;
console.log('notificare');
break;
case 'SolduriConcedii':
//Form Field Internal name
fd.field('zileConcediu').value = props[i].Value;
break;
}
}
var subdiv = niv1;
if (niv2 != "") {
subdiv += "/" + niv2
}
if (niv3 != "") {
subdiv += "/" + niv3
}
fd.field('Subdiviziunea').value = subdiv;
var sector = "";
if (tip == "C") {
sector = "Centrala";
} else if (tip == "S") {
sector = "Retail";
} else if (sec == "IMM") {
sector = "IMM";
} else {
sector = "Retail";
}
fd.field('Sector').value = sector;
//daca sunt exceptii
manageriExceptie(_spPageContextInfo.userId);
});//pnp
}
updateUserInfo2();
});
//functia care cauta exceptiile de manageri in lista de exceptii si rescrie bosii
function manageriExceptie(AngajatId){
pnp.sp.web.lists.getByTitle("Concedii Excepții Manageri").items.select("Title", "Id", "AngajatId", "BossLevel1/Name", "BossLevel2/Name", "BossLevel3/Name", "Notificare/Name").expand("BossLevel1", "BossLevel2", 'BossLevel3','Notificare').filter("AngajatId eq '"+AngajatId+"'").get().then(function (results) {
console.log(results)
if (results.length > 0) {
var names=[];
if (results[0].BossLevel1 !== undefined) {
for (var i = 0; i < results[0].BossLevel1.length; i++) {
names.push(results[0].BossLevel1[i].Name);
}
fd.field('Boss_x0020_Level_x0020_1').value = names;
} else if (fd.field('Boss_x0020_Level_x0020_1').value!==undefined){
//fd.field('Boss_x0020_Level_x0020_1').value=null;
fd.field('Boss_x0020_Level_x0020_1').clear();
}
names=[];
if (results[0].BossLevel2 !== undefined) {
for (var i = 0; i < results[0].BossLevel2.length; i++) {
names.push(results[0].BossLevel2[i].Name);
}
fd.field('Boss_x0020_Level_x0020_2').value = names;
} else if (fd.field('Boss_x0020_Level_x0020_2').value!==undefined){
//fd.field('Boss_x0020_Level_x0020_2').value=null;
fd.field('Boss_x0020_Level_x0020_2').clear();
}
names=[];
if (results[0].BossLevel3 !== undefined) {
for (var i = 0; i < results[0].BossLevel3.length; i++) {
names.push(results[0].BossLevel3[i].Name);
}
fd.field('Boss_x0020_Level_x0020_3').value = names;
} else if (fd.field('Boss_x0020_Level_x0020_3').value!==undefined){
//fd.field('Boss_x0020_Level_x0020_3').value=null;
fd.field('Boss_x0020_Level_x0020_3').clear();
}
names=[];
if (results[0].Notificare !== undefined) {
for (var i = 0; i < results[0].Notificare.length; i++) {
names.push(results[0].Notificare[i].Name);
}
fd.field('Notificare').value = names;
} else if (fd.field('Notificare').value!==undefined){
//fd.field('Notificare').value=null;
fd.field('Notificare').clear();
}
}//if result>0
});//pnp
}
fd.spRendered(function() {
// set json to DataTable
function filterD11T(){
if (fd.field("zileConcediu").value && fd.field("zileConcediu").value.length>6 ){
var jsonArray = JSON.parse(fd.field("zileConcediu").value);
fd.control("DataTable1").widget.setOptions({dataSource:jsonArray});}
fd.control('DataTable1').disabled = true;
// hide grid-toolbar
var gridRoles = fd.control('DataTable1').widget;
gridRoles.element.find(".k-grid-toolbar").hide();
}
fd.field('zileConcediu').$on('change', filterD11T)
filterD11T();
});
Margo
(Margo)
September 15, 2022, 11:18am
7
@ixxxl ,
Run this code in the Internet Explorer console:
navigator.userAgent
and share the screenshot of the result.
Margo
(Margo)
September 15, 2022, 2:00pm
9
@ixxxl ,
Please comment out all custom code and test this one in Internet Explorer:
fd.spRendered(function() {
if (navigator.userAgent.toLowerCase().indexOf('trident') > -1) {
alert('Utilizati Chrome sau EDGE');
return fd.close();
}
});
ixxxl
(ixxxl)
September 16, 2022, 5:08am
10
@Margo
works good! how to combine it with all code? when i put it back, it doesn't work.
Margo
(Margo)
September 16, 2022, 10:09am
11
@ixxxl ,
You must add this code before the rest of your code. Also note that you must put all the code into one spRendered function. There is no need to wrap every part of the code into spRendered.
ixxxl
(ixxxl)
September 16, 2022, 10:17am
12
@Margo
doesn't work... i put all code in 1 spRendered.
window.fd=fd
fd.spRendered(function() {
if (navigator.userAgent.toLowerCase().indexOf('trident') > -1) {
alert('Utilizati Chrome sau EDGE');
return fd.close();
}
function filterCategory(cat) {
//example filtering by one field
// var linieID = linie && linie.LookupId || linie || null;
var filter = '1';
fd.field('Sucursala').filter = "suc eq '" + filter + "'";
fd.field('Sucursala').widget.dataSource.read();
};
fd.field('Sucursala').ready().then(function() {
//filter Categories when form opens
filterCategory();
});
function listControl(){
fd.control('SPDataTable1').readonly=true
fd.field('Group').disabled = true
}
listControl();
function suc() {
fd.field('Cod_x0020_Sucursala').value = fd.field('Sucursala').value.Cod_x0020_Subdiviziune
if (!fd.field('Cod_x0020_Sucursala').value) {
fd.control('SPDataTable1').readonly = true
} else {
fd.control('SPDataTable1').readonly = false
}
}
fd.field('Sucursala').$on('change', suc)
function dep() {
const cod = fd.field('Cod_x0020_Sucursala').value
fd.field('Group').disabled = true
fd.field('Group').value = `S${cod}-RTL-Director;S${cod}-RTL-SpPrin;S${cod}-RTL-SefCasa;`
}
fd.field('Cod_x0020_Sucursala').$on('change', dep)
fd.control('SPDataTable1').ready().then(function (dt) {
//dt parameter is the same as fd.control('SPDataTable0')
console.log('SPDataTable7 is initialized');
//set width and height:
fd.control('SPDataTable1').dialogOptions = {
width: 1280,
height: 720
}
});
});
Margo
(Margo)
September 19, 2022, 5:08am
13
@ixxxl ,
Obviously, the error is caused by your custom code, but I can't tell you which part. You can debug your code, find instructions here .
ixxxl
(ixxxl)
September 19, 2022, 5:19am
14
@Margo
i tried ,but it returns fd undefined. but this code works fine in chrome, edge, firefox
Margo
(Margo)
September 19, 2022, 8:28am
15
@ixxxl ,
There is a syntax error in this line:
It must be:
window.$ = $;
ixxxl
(ixxxl)
September 19, 2022, 8:37am
16
@Margo
changed, the same error.. may be it is possible to first verify which browser it is, and then after 2-3 seconds to start all rest of the code ?
Margo
(Margo)
September 20, 2022, 6:38am
17
@ixxxl ,
You can try out using the setTimeout() method , but that won't resolve the error in your code.
Please export the form and send it to me and I will check the code. There is an invalid character that should be easy to find.
ixxxl
(ixxxl)
September 20, 2022, 6:42am
18
Margo
(Margo)
September 20, 2022, 8:04am
19
@ixxxl ,
This line breaks the whole code in IE:
fd.field('Group').value = `S${cod}-RTL-Director;S${cod}-RTL-SpPrin;S${cod}-RTL-SefCasa;`
You need to change it for instance like this:
const str = 'Hello' + ' ' + 'World'
1 Like
ixxxl
(ixxxl)
September 20, 2022, 8:11am
20
@Margo
Thanks ! for now it works!
it seems that explorer doesn't support template literals.
How did you get it ?