Are there any tricks to toggling the visibility of...
# suitescript
j
Are there any tricks to toggling the visibility of a field client-side? (Field is added in a
beforeLoad
user event if that matters). I have it start off hidden and only want to make it visible later on if certain conditions are met client-side.
Copy code
const field = ctx.currentRecord.getField({ fieldId: 'custpage_item' });
field.isDisplay = true; // does not work
field.isVisible = true; // does not work
k
I have this setup in a custom module as you need the use.updateFieldDisplayType({options})
You need to pass in the options of the type and true or false.
j
Oops I wasn't clear that I'm trying to change the visibility client side and far as I can tell
updateFieldDisplayType
is only available to server scripts as part of the
N/ui/serverWidget
module 🙁 I decided to just leave have it start off disabled and then enable it using
field.isDisabled = true
which works fine.
k
I am doing loads of hiding and showing in client script on the customer form for application fields and I for the life of me cannot remember what I am using to do it. If I was at my computer I could tell you straight away. I will let you know tomorrow as it tool me ages to figure it out. I have them built in a custom module so i can just call them easier when needed.
@jkabot I have this setup in my custom module like the below.
Copy code
function disableField(currentRecord,myFieldID,truefalse) {
		var disable = currentRecord.getField({fieldId: myFieldID}); // myFieldID is the second parameter passed through on the function from the client script.
		disable.isDisabled = truefalse; // disable said field
	}
Copy code
function displayField(currentRecord,myFieldID,truefalse) {
        var display = currentRecord.getField({fieldId: myFieldID}); // myFieldID is the second parameter passed through on the function from the client script.
        display.isDisplay = truefalse; // hide said field
    }
Copy code
function makeMand(currentRecord,myFieldID,truefalse) {
        var makeMand = currentRecord.getField({fieldId: myFieldID}); // myFieldID is the second parameter passed through on the function from the client script.
        makeMand.isMandatory = truefalse; // hide said field
    }
Hope that helps.
j
Thanks. Looks like
isDisplay
should work (in theory). I think my case might be different because I started it off hidden server side (and would only become unhidden client side). I ended up compromising by starting it off disabled server side (and later enabling it client side), which works for what I need
k
Think it would work both ways TBH