What is alert box ?
Alert box is a small container which displays user message in blocking mode that means user can't do any other action in the window.
Is there any standard way of doing it ?
As of now, there's no standard component to display the alert box in the page.How to build a custom one ?
Traditionally, developers use window.alert function to display the box in the page. This is done different places in the project & it looks very cluttered to go through the code.What are the alternatives ?
Some developers like to use some dialog box from javascript libraries like Jquery, Backbone in blocking mode. Though, it will give the necessary functionality, it's an additional overhead in the page.Where is the code ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:component > | |
<apex:attribute type="String" name="value" description="The message to be displayed to the user"/> | |
<script> | |
if (document.readyState == 'complete') { | |
window.alert('{!value}'); | |
} | |
</script> | |
</apex:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page > | |
<apex:form> | |
<!-- | |
Show Box After an Action from Button, Link, JS Action Function call, etc | |
All you need to do is, add the Id of the alert box in the reRender list. | |
--> | |
<apex:commandButton value="Show AlertBox1" reRender="MyAlertBox1"/> | |
<apex:commandButton value="Show AlertBox2" reRender="MyAlertBox2"/> | |
</apex:form> | |
<c:alertBox value="Message1 from AlertBox1" id="MyAlertBox1"/> | |
<c:alertBox value="Message2 from AlertBox2" id="MyAlertBox2"/> | |
</apex:page> |
No comments:
Post a Comment
Thanks for reading my blog !