(window.top) - hide/ show controls from sub forms or dialogue forms

Hello,

in order to set a value for a parent form from a sub form i am using this script below and it is working perfectly:

fd.spBeforeSave(function () {
window.top.fd.field('PersonHasChildrens').value = false;
window.top.fd.field('PersonChildrensCount').clear();
});

what is the the right script that i can use to hide or show these controls above, usually i use this code in parent form and it work for me:
//for hide
$(fd.field('PersonHasChildrens').$parent.$el).hide();
$(fd.field('PersonChildrensCount').$parent.$el).hide();
//to show
$(fd.field('PersonHasChildrens').$parent.$el).show();
$(fd.field('PersonChildrensCount').$parent.$el).show();

now i need to use the same code but from the subform/child form in order to show or hide controls in parent form
i tried to add: "window.top" like this but it seems not correct:
//to show
$(window.top.fd.field('PersonHasChildrens').$parent.$el).show();
$(window.top.fd.field('PersonChildrensCount').$parent.$el).show();

thank you for the help

Hello @gkhadra,

I have two options for you. Please choose the one you like most.

  • You can use the following code to show controls in the parent form:

    $(window.top.fd.field('PersonHasChildrens').$parent.$el, window.top).show();

  • The second option is to define $ globally in the parent form:

    window.$ = $;

    And in the child form the code to hide control in the parent form will be:

    window.top.$(window.top.fd.field('PersonHasChildrens').$parent.$el).show();

Hello dear @mnikitina,
really thank you for your help, the second option is simplified and very nice.

One more Question please
is it enough to use this below script inside a function in order to check if a lookup control is ready, or do i need to do something else?:

Script:
window.top.fd.field("PersonMaritalStatus").ready().then(function () ....

Using function:
function fncCheckMaritalType() {
window.top.fd.field("PersonMaritalStatus").ready().then(function () {
if ($.inArray(window.top.fd.field('PersonMaritalStatus').value.LookupId, ArrMaritalStatusSubToHide) !== -1) {
HusbWifeHIDEControls();
} else if ($.inArray(window.top.fd.field('PersonMaritalStatus').value.LookupId, ArrMaritalStatusSubToShow) !== -1) {
HusbWifeSHOWControls();
}
SubProcLinkFamily();
});
}

sometimes is working sometime is not, weird!!!

@gkhadra,

Could you please give more details about what you are trying to achieve.

Does the 'PersonMaritalStatus' field is a lookup field or multiple-choice lookup field?

What data stored in 'ArrMaritalStatusSubToHide'?

Hello @mnikitina,

-'PersonMaritalStatus' is a lookup field for a list contains Marital status types (data are fixed no changes will be made on this list).

  • 'ArrMaritalStatusSubToHide' is an array already declared and contains multiple integers ID like: 2,3,6,9...
    These IDs are selected from the Martial status types list to check if the lookup value will match one of those IDs if matched i will call a function to show some controls if else i will call another function to hide controls.

First request kindly I need to be sure that i am writing the right script to check if the lookup field 'PersonMaritalStatus' is ready in the parent form, from the sub form or i need to change this:
Window.top.fd.field("PersonMaritalStatus").ready().....

Secondly, I tried to debug my scripts as i see the problem is with the Lookup field value.

Sometimes this script works with any lookup field:
($.inArray(window.top.fd.field('PersonMaritalStatus').value.LookupId, ArrMaritalStatusSubToShow) !== -1)

If not i need to change to this script:
($.inArray(window.top.fd.field('PersonMaritalStatus').value, ArrMaritalStatusSubToShow) !== -1)

You can check the difference above between
fd.field(Lookup).value.LookupId
And
fd.field(Lookup).value

somtimes none of those works too so i used this below and it worked:
fd.field(Lookup).value.ID

It should be 1 right solution/script to get a straight Lookup value.

Thanks for your time i am waiting your advise.

@gkhadra,

You can get the lookup field value ID from the parent form using the following:

window.top.fd.field('InternalLookupFiledName').value.ID;

If the 'PersonMaritalStatus' field has any filtration?

Hello thank you i will use this script and get back to you in case of problem.

No filtration.

But i have another lookup with filtration, do i need to change the script to get value if yes kindly advise what i should do??

@gkhadra,

I've tested the fields with filtration getting values from the parent record to the child should work fine.

In any case, you can contact us for assistance anytime.