Patrick Kelly
Posts: 0
Joined: Wed Nov 20, 2013 6:00 am

How can you use Javascript to make a button invisible?

I am using a REST service to fill information inside a template page. Basically, I duplicate the page, put the ID into a field, and it auto fills in the page. However, not all IDs have all the fields defined. As of now, that means that I get buttons that display "undefined" as the final result.

Is there something in the Appery documentation that allows you to change a button from visible to invisible? I plan on using an if/else statement. If the REST service returns "undefined", then I want to tell the object to no longer be visible.

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

How can you use Javascript to make a button invisible?

This will hide a button
Apperyio('mybutton').hide();

And this will show it
Apperyio('mybutton').show();

Just remember to replace the button name with the name of your component

And same method should apply to other appery components too

Patrick Kelly
Posts: 0
Joined: Wed Nov 20, 2013 6:00 am

How can you use Javascript to make a button invisible?

Awesome, thanks for all the help. Any advice for the most efficient way to check if a particular column returns undefined?

Example

ID_______FirstNameMiddleNameLast Name
jsufkeu39238John_________________Doe

Since the "MiddleName" column is blank, it will return "undefined". I have tried using an if statement if the resulting button text reads "undefined", but that doesn't work. When I use an alert to telly me what the value of the button is, it's actually:

"function ( value ) {
return jQuery.access( this, function( value ) {
return value === undefined ?
jQuery.text( this ) :
this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) );
}, null, value, arguments.length );
}"

even though the button itself only displays "undefined".

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

How can you use Javascript to make a button invisible?

You can do something like this to check for undefined

if (value !== "undefined" || !value) {
// Value is not equal to undefined / empty string
}

You can also use it in the JS - on the Success mapping. Then based on this condition return a different string, for example

if (value !== "undefined" || !value) {
// Value is not equal to undefined / empty string
return "Hello" + " " + value;
}
else {
return "Value doesn't exist";
}

Patrick Kelly
Posts: 0
Joined: Wed Nov 20, 2013 6:00 am

How can you use Javascript to make a button invisible?

Will this work if 4/5 columns return values, but only one is undefined?

Patrick Kelly
Posts: 0
Joined: Wed Nov 20, 2013 6:00 am

How can you use Javascript to make a button invisible?

I think that I explained my predicament a lot better in this post:

https://getsatisfaction.com/apperyio/...

You have already helped so much tonight, if I can get this last bug worked out, then I'm home free. At least for now. Your help would be much appreciated.

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

How can you use Javascript to make a button invisible?

hi,

You can do that check for each of those values - OR only for those you require. I'll have a look at the other post in a while

Patrick Kelly
Posts: 0
Joined: Wed Nov 20, 2013 6:00 am

How can you use Javascript to make a button invisible?

I looked at your comment on the other thread and things made a lot more sense. However, the functions you provided here didn't seem to quite reach the goal. Website now says "Hello undefined". I'll fool around a bit longer, I've been looking at some documentation and might be able to make this work with the help you've given so far.

Patrick Kelly
Posts: 0
Joined: Wed Nov 20, 2013 6:00 am

How can you use Javascript to make a button invisible?

GOT IT! Thank you so much for pointing me in the right direction. In the end, this was the code that worked:

if (typeof value === "undefined") {
// Value is undefined.
Appery("bizWeb").hide();
}
else {
return value;
}

Bruce Stuart
Posts: 0
Joined: Fri Oct 24, 2014 4:42 am

How can you use Javascript to make a button invisible?

I believe that undefined is a constant ... So the statement is:

If ( somevariable === undefined ) { do something }

You can test this at the command prompt in most debuggers.

Bruce

Return to “Issues”