Hi,
Can i close parent form automatically when is closing child form?
I tried to use inline list and library control populate from parent, but it is empty...
fd.spRendered(function() {
//prepopulating fields of a new record
//with the values from the parent form
fd.control('SPDataTable2').$on('edit', function(editData) {
//check that this is a new record
if (editData.formType === 'New') {
//prepopulating due date
editData.field('Utilizator').value = fd.field('Author').value;
editData.field('Title').value = fd.field('Title').value
}
});
});
Does it works only in Online ? i have On-prem. (see some info about this that's work only in Online)
If so, than i need to close parent form automatically when is closing child form...
function checkRecords() {
var currentCount='';
var newCount = fd.control('SPDataTable2').widget.dataItems().length;
if(newCount > currentCount){
currentCount = newCount;
fd.close();
}
else if(newCount < currentCount) {
currentCount = newCount;
}
}
fd.spRendered(function() {
var currentCount = fd.control('SPDataTable2').widget.dataItems().length;
var myVar = setInterval(checkRecords, 2000);
});
I resolved with dataItems.
There is one more - currentCount - not definied if it is not in the code. and as i put - var currentCount=''; it closes on opening...
@Margo
There is one more - currentCount - not definied if it is not in the code. and as i put - var currentCount=''; it closes on opening...and i can't do anything...can't create child
what should i put in var currentCount ?
i open parent form, the child have some elements from other users. and i try to navigate to add one more new child, the form is closing...no erros in console.
it seems that works first one that newCount have for example 10 > than currentCount that by default have 0
newCount i think must be like currentCount +1 . but when.....
Some code after creating new item maybe?
@Margo
now root folder doesn't appear in list library and i can't add new item ib list and library.
There is one more error in console
The code seems no errors
window.fd=fd;
fd.spRendered(function () {
//get all buttons
function Store() {
/* var selected = fd.field('Categorii_x0020_de_x0020_adresa_').value;
var s = '';
for (var i = 0; i < selected.length; i++) {
s += selected[i].LookupValue + '; ';
}
//Set field values with the values from the parent on form load
fd.field('cat').value = s;*/
if (typeof(Storage) !== "undefined") {
// Code for localStorage/sessionStorage.
sessionStorage.lastname = fd.field('cat').value;
sessionStorage.boss = fd.field('Boss1').value;
} else {
// Sorry! No Web Storage support..
alert('Ahtung');
}
}
//fd.field('Categorii_x0020_de_x0020_adresa_').$on('change', Store);
Store();
})
window.fd = fd;
fd.spRendered(function () {
//get all buttons
function setFieldPropreties() {
//Disable Sharepoint Save field
// fd.toolbar.buttons[0].style = "display: none;";
fd.toolbar.buttons[1].text = "Editează";
fd.toolbar.buttons[1].text = "Închide";
//Hide system fields
$('.sysfields').hide();
$('.motiv').hide();
// Disable edit la cimpurile populate
// fd.field('Data_x0020_aprob_x0103_rii').required = true;
// fd.field('Data_x0020__x00ee_ntr_x0103_rii_').required = true;
// fd.field('Tip_x0020_de_x00Stare_x0020_ANI20_produs').required = true;
// fd.field('Versiune_x0020_ANI').required = true;
fd.field('Statut_x0020_Confirmare').disabled = false;
// fd.field('UID').required = true;
}
// executes setFieldPropreties on form load
setFieldPropreties();
});
fd.spRendered(function () {
fd.control('SPDataTable1').ready().then(function (dt) {
//dt parameter is the same as fd.control('SPDataTable0')
console.log('SPDataTable1 is initialized');
fd.control('SPDataTable1').buttons[0].text = 'Adăugați versiune ANI';
//set width and height:
fd.control('SPDataTable1').dialogOptions = {
width: 1280,
height: 720
}
});
fd.control('SPDataTable4').ready().then(function (dt) {
//dt parameter is the same as fd.control('SPDataTable0')
console.log('SPDataTable4 is initialized');
fd.control('SPDataTable4').buttons[0].text = 'Button disabled';
//set width and height:
fd.control('SPDataTable4').dialogOptions = {
width: 1280,
height: 720
}
});
fd.control('SPDataTable2').ready().then(function (dt) {
//dt parameter is the same as fd.control('SPDataTable0')
console.log('SPDataTable2 is initialized');
fd.control('SPDataTable2').buttons[0].text = 'Adăugați confirmare ANI';
//set width and height:
fd.control('SPDataTable2').dialogOptions = {
width: 1280,
height: 720
}
});
fd.control('SPDataTable3').ready().then(function (dt) {
//dt parameter is the same as fd.control('SPDataTable0')
console.log('SPDataTable3 is initialized');
fd.control('SPDataTable3').buttons[0].text = 'Adăugați comentarii ANI';
//set width and height:
fd.control('SPDataTable3').dialogOptions = {
width: 1280,
height: 720
}
});
});
/*fd.spRendered(function(ctx) {
var dt = fd.control('SPDataTable2');
dt.ready().then(function() {
setRootFolder();
});
//set root folder when Category field changes
fd.field('Title').$on('change', function() {
setRootFolder();
});
function setRootFolder(){
var category = (fd.field('ID').value +'_' +fd.field('Title').value)
dt.baseRootFolder = category;
dt.rootFolder = category;
}
});
*/
fd.spRendered(function () {
function setFieldPropreties1(){
if (fd.field('Statut_x0020_Confirmare').value == null || fd.field('Statut_x0020_Confirmare').value == ""){
fd.field('Statut_x0020_Confirmare').placeholder ='Indicați statut de confirmare';
fd.control('Button1').disabled = true;
}else {
fd.control('Button1').disabled = false;
}
}
// Calling setPercentComplete when the user changes the status
fd.field('Statut_x0020_Confirmare').$on('change',setFieldPropreties1);
setFieldPropreties1();
});
/*var newCount = 0;
var currentCount = 0;
function checkRecords() {
newCount = fd.control('SPDataTable2').widget.dataItems().length;
if(newCount > currentCount){
currentCount = newCount;
fd.close();
}
else if(newCount < currentCount) {
currentCount = newCount;
}
}
fd.spRendered(function() {
fd.control('SPDataTable2').ready().then(function(dt) {
currentCount = fd.control('SPDataTable2').widget.dataItems().length;
var myVar = setInterval(checkRecords, 2000);
});
});
*/
var newCount = 0;
var currentCount = 0;
function checkRecords() {
newCount = fd.control('SPDataTable2').widget.dataItems().length;
if(newCount > currentCount){
currentCount = newCount;
fd.close();
}
else if(newCount < currentCount) {
currentCount = newCount;
}
}
fd.spRendered(function() {
var dt = fd.control('SPDataTable2');
dt.ready().then(function() {
setRootFolder();
currentCount = fd.control('SPDataTable2').widget.dataItems().length;
var myVar = setInterval(checkRecords, 2000);
});
//set root folder when Category field changes
fd.field('Title').$on('change', function() {
setRootFolder();
currentCount = fd.control('SPDataTable2').widget.dataItems().length;
var myVar = setInterval(checkRecords, 2000);
});
function setRootFolder(){
var category = fd.field('Title').value;
dt.baseRootFolder = category;
dt.rootFolder = category;
}
});
P.S
I changed to var category = (fd.field('ID').value +'_' +fd.field('Title').value) and now root folder works.
But the same result on opening main form it is closing after 2-3 seconds....
It is better to have one spRendered function and add run all code within it.
I can't tell which part of your code breaks the logic of the code that I've provided. You can debug your code, following the suggestions from this post:
fd.spRendered(function(ctx) {
var dt = fd.control('SPDataTable2');
dt.ready().then(function() {
setRootFolder();
});
//set root folder when Category field changes
fd.field('Title').$on('change', function() {
setRootFolder();
});
function setRootFolder(){
var category = (fd.field('ID').value +'_' +fd.field('Title').value)
dt.baseRootFolder = category;
dt.rootFolder = category;
}
});
var newCount = 0;
var currentCount = 0;
function checkRecords() {
newCount = fd.control('SPDataTable2').widget.dataItems().length;
if(newCount > currentCount){
currentCount = newCount;
fd.close();
}
else if(newCount < currentCount) {
currentCount = newCount;
}
}
fd.spRendered(function() {
fd.control('SPDataTable2').ready().then(function(dt) {
currentCount = fd.control('SPDataTable2').widget.dataItems().length;
alert('current'+currentCount)
var myVar = setInterval(checkRecords, 2000);
});
});
one open form it's closing after 2 seconds. The reason is setting root folder. Is it a way some kind assinhron start code maybe ... because when is setting root folder it didn't need to run part with closing parent..only after adding new item in child.
P.S . Trying your code published earlier - works on root folder, and the same is closing after 2 seconds..
@Margo
Now it works thank you !!
One more thing that i found. When i open the form and in list and library there are more then 30 items it have arrows to list to another 30 items. when i press next - it alerts deleted as in the code:
I press ok, and then press back arrow - the alert is new item. and after that i added closing form, and its closes without adding new item in list\library control
@Margo
Hello
There is a problem, when library and list control have more than 30 items .. Because in display view of parent form it show only 30(for example) and when you create new item it shows now 30 items... and code can't count items in table. it works only undo 30 items. until it can count in view.