FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.



May 7, 2013, 7:09 PM
90 Posts

Hide when

  • Category: Other
  • Platform: All
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 4
 
I want this button to "hide when" if *either* of the following two things are true:

if the status is Final, or, if the document is in read mode (i.e. not in edit mode).

I still don't really grok yet how that, which was straightforward in Notes, is done in xPages now.   Any help appreciated.

<xp:button value="Save As Draft" id="SubmitDraft" styleClass="buttonred">
        <xp:this.rendered><![CDATA[#{
                 javascript:var tempstatus = getComponent("Status").getValue();
                tempstatus != "Final"}]]>
                 </xp:this.rendered>
        <xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="true" id="SaveAsDraft">
            <xp:this.action>
                <![CDATA[#{javascript:
                Submission.replaceItemValue("Status","Draft");
                Submission.save();
                var url="web.nsf" + "/xThankYouDraft.xsp";
                context.redirectToPage(url);
}]]> 
May 7, 2013, 8:55 PM
110 Posts
Re: Hide when
 Compute this into the 'Visible' property of the button:


Submission.getItemValueString('Status')!='Final'||Submission.isEditable() 
May 8, 2013, 10:34 AM
90 Posts
Re: Hide when
Thanks Baxter, that got me thinking. I modified a bit what you suggested, as ... if the document was not in edit mode -- then that needed to override the status check, rather than be equal to it as an OR.

 here's my hidewhen that is working. if doc isn't in edit mode, then don't render this element visible. if it is in edit mode, and the status field is not set to final, then do render this element visible. Otherwise, don't render it visible.

Probably really wordy coding, but it's working, for the sake of others who are desperate:

        var show = "";
        if (!Submission.isEditable()) {show = "No"}
        else if (Submission.getItemValueString('Status')!='Final') { show = "Yes"}
        show == "Yes";  
May 8, 2013, 9:35 PM
453 Posts
Re: Hide when
Understand that the Visible property is not the same as the Notes Hide-When. The Visible property actually controls if a control is even rendered. Setting the Visible to False stops the control value from even being present on the XPage. I can't say how long I fought with this until I realised what was happening. If you want the control hidden but it's value available then you need to set the Style="display:none". The display:none functions more like the Hide-When than the Visible does.  I use the style="display:none" almost as much as I use the visible property. If you notice if you enter a formula into the visible property, the formula appears on the All Properties under the Render property. I think this is a bit of unfortunate naming. I think the Visible property should be called Rendered so it is consistent. To me the visible property would be better to set the display:none in the style.

Would have saved me several hours of experimenting until I finally got that straight. 
May 9, 2013, 2:06 PM
366 Posts
Re: Hide when
Some more information.


Via SSJS, if the "Loaded" property is true and the "Rendered" property is false then the value stored in the component is still available programmatically as it is loaded in the component tree but not displayed.


From CSJS the values are ONLY available in document "Edit" mode. 


 

FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.