Alpha Video Training
Results 1 to 10 of 10

Thread: Accessing {dialog.ComponentName} onInitializeComplete

  1. #1
    Member
    Real Name
    Cameron Smith
    Join Date
    Oct 2018
    Posts
    16

    Default Accessing {dialog.ComponentName} onInitializeComplete

    Hey there!

    I've created a button list that's being driven from a data series. Occasionally, the data can cause the button list to take up more space than the page has, which creates a scrollbar at the bottom.

    To get around this, I wanted to style the parent ButtonList control to use the CSS grid to effectively "wrap" my buttons around the page.

    So, in the onInitializeComplete client-side event, I used JavaScript to adjust the styling of the control (because for some reason no styling properties are available in Alpha for button lists). Initially I hardcoded the ID, like this:

    Code:
    document.getElementById("DLG1.V.R1.SELECT_PROJECT.CONTROL").style = "display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 1px;"
    This worked. However, when I published to the server, the component name changed. So I tried to use the {dialog.ComponentName} placeholder to grab the component name, like so:

    Code:
    document.getElementById({dialog.ComponentName} + ".V.R1.SELECT_PROJECT.CONTROL").style = "display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 1px;"
    Here's the weird thing... now I'm getting an error:

    VM1111:411 Uncaught ReferenceError: TBI_UX_DASH_16651DGEJ is not defined

    When I inspect my controls, this is indeed the appropriate component name. What's weirder is that if I hard-code the component name that's showing on the server, it can select & style the element just fine. Is onInitializeComplete firing before the component is fully initialized perhaps? Would there be a better event to place this code in, or a better way of styling the ButtonList without using JavaScript that I'm missing entirely?

    Thank you!

  2. #2
    "Certified" Alphaholic
    Real Name
    Rich Fulham
    Join Date
    May 2011
    Location
    Portland, OR
    Posts
    1,002

    Default Re: Accessing {dialog.ComponentName} onInitializeComplete

    Try this in your onInitializeComplete:


    Code:
    var btnLstObj = {dialog.Object}.getControl('BtnLst');
    var btnCont = $(btnLstObj.contId);
    alert(btnCont.style.cssText );
    btnCont.style.display = "grid";
    btnCont.style.gridTemplateColumns = "repeat(3, 1fr)";
    btnCont.style.gridGap = "1px";
    alert(btnCont.style.cssText );
    If the second alert does not include the properties that were set then your browser does not support the new "grid" style properties. So, typically this won't work in "Working Preview" or "Live Preview" unless you have configured Alpha to using something other than IE.

    1) There are multiple ways to get the container element for the button list. I used the UX "getControl" method to get the JavaScript object that Alpha sets up for the ButtonList and from there I used its 'contId' property and used the jQuery shortcut to get a DOM element pointer (btnCont).

    2) When you have a pointer to a DOM element you cannot set the properties all at once using your syntax. There is probably some way to do it, but I'm just used to setting each property individually. Also, watch out, the property names are different than what CSS text uses. I use the Chrome Developer Tools to inspect the DOM element and get the property names from that. (I'm always worried that some browsers may have chosen different property names. So, if someone can show how to set these using CSS Text property names then that would probably be a better way to go.

    3) I have only used the ButtonList on the Detail View container attached to a LIST. And, under that condition the ButtonList is always recreating itself from scratch. This means setting any DOM element properties of the button list container or any of its buttons must be done every time Alpha refreshes the button list. That is, using "onInitializeComplete" would not be sufficient. I don't know if the ButtonList gets recreated from scratch when it is on the main part of a UX. At a minimum, I think you would also need this code in the 'onSynchronizeDialog' - that embed gets called when a cached UX is re-used. In which case, I don't think 'onInitializeComplete' gets called. In my UX, I use the 'onRenderComplete' instead of 'onInitializeComplete', along with 'onSynchronizeDialog'.

    4) This point is for ALPHA SOFTWARE - There are two critical events that the ButtonList needs to provide access to, for us to interject custom javascript:
    a) Before the ButtonList is "Refreshed", and
    b) After the ButtonList is "Refreshed"
    This is where code to achieve the OP's effect should be embedded (after button is "Refreshed").
    The "Before Refresh" embed is needed, so the ButtonList object can be tweaked, like when its "Theme" needs to be removed. Or, at a minimum the ButtonList needs to have an internal property that says to not include the UX's Theme and/or replace the Theme with something else or blank.

    5) The ButtonList can do a whole lot more when you set its properties manually instead of using only what the UX ButtonList builder allows.
    Last edited by RichCPT; 02-28-2019 at 01:38 PM. Reason: some typos fixed.

  3. #3
    "Certified" Alphaholic
    Real Name
    Rich Fulham
    Join Date
    May 2011
    Location
    Portland, OR
    Posts
    1,002

    Default Re: Accessing {dialog.ComponentName} onInitializeComplete

    Oh, for an easy solution: I think you could create a "local CSS" class with the properties that you want and then in the ButtonList properties, set the "Control container class name".
    You probably have to include "!important" at the end of your CSS properties, because Alpha usually likes to override anything you do, by putting their CSS class name after yours instead of giving you three options: 1) omit Alpha class, 2) put Alpha class first, 3) put Alpha class last.

  4. #4
    Member
    Real Name
    Cameron Smith
    Join Date
    Oct 2018
    Posts
    16

    Default Re: Accessing {dialog.ComponentName} onInitializeComplete

    Rich,

    You are awesome my friend! I actually did try your second solution before posting (replacing the A5CW container with my own class), but the properties weren't being applied. I'll try it with !important added, and if that doesn't work, I'll give your first solution a try. Thank you so much!

  5. #5
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,571

    Default Re: Accessing {dialog.ComponentName} onInitializeComplete

    Quote Originally Posted by Cameron.Smith View Post
    This worked. However, when I published to the server, the component name changed. So I tried to use the {dialog.ComponentName} placeholder to grab the component name, like so:

    Code:
    document.getElementById({dialog.ComponentName} + ".V.R1.SELECT_PROJECT.CONTROL").style = "display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 1px;"
    Your syntax is a bit off... you don't use a placeholder like that in this situation. I also get an error when using your syntax. Use this instead...

    Code:
    document.getElementById("{dialog.ComponentName}.V.R1.SELECT_PROJECT.CONTROL").style = "display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 1px;"
    The placeholder goes inside the double quotes... and gets evaluated as part of the string.
    Last edited by Davidk; 02-28-2019 at 05:53 PM.

  6. #6
    "Certified" Alphaholic
    Real Name
    Rich Fulham
    Join Date
    May 2011
    Location
    Portland, OR
    Posts
    1,002

    Default Re: Accessing {dialog.ComponentName} onInitializeComplete

    If it does not work then its probably due to another inner container <div> that needs to have the properties set. There are two nested <div> and alpha applies the specified class to the outer div, which causes problems when setting attributes that are not inheritable.

    This example accomplishes setting a fat border around the buttons:

    (In the UX Local CSS):
    Code:
    .myButtonWrapper {
    background-color: PapayaWhip !important;
    border: 5px !important solid Bisque !important;
    padding: 10px !important;
    }

    ButtonList "Control container class name" = myButtonWrapper

    If the CSS attributes have to be set on the inner HTML then I guess you'd have to get an element pointer to it and use JavaScript as previously discussed. If the ButtonList is on the main part of a UX then I think the following should work to get a pointer to the inner <div>:

    var id = '{dialog.ComponentName}.V.R1.BTNLST.CONTROL';
    var ele = $(id);
    $acn( ele, 'myButtonWrapper');

    Replace 'BTNLST' with the name/id of your ButtonList.
    I used multiple lines of code, so it is easier to debug.
    Last edited by RichCPT; 02-28-2019 at 05:26 PM. Reason: added $acn to Add Class Name to element.

  7. #7
    "Certified" Alphaholic
    Real Name
    Rich Fulham
    Join Date
    May 2011
    Location
    Portland, OR
    Posts
    1,002

    Default Re: Accessing {dialog.ComponentName} onInitializeComplete

    Here's Mozilla's documentation on setting style properties via JavaScript (Notice they say do not set "elt.style" to a string as that property is supposed to be read-only. For multiple assignments, use: elt.style.cssText = "css style attributes in kebab-case"

    https://developer.mozilla.org/en-US/...LElement/style

  8. #8
    Member
    Real Name
    Cameron Smith
    Join Date
    Oct 2018
    Posts
    16

    Default Re: Accessing {dialog.ComponentName} onInitializeComplete

    Y'all are amazing! I was able to incorporate your solutions and get it working! Here's some lessons learned:

    1) David was absolutely right - if I put {dialog.ComponentName} within the string it works just fine.
    2) Thanks to Rich, I learned two new things: properly styling using JavaScript and a new function from Alpha for adding classes ($acn). Using the JavaScript you provided, I was able to target the button list control and add my wrapper classes to the two controls that needed them.

    Oh and Rich, P.S.: I tried doing control container class without using JavaScript but that method didn't have any luck :(. Could have been something from my end - it's certainly been a Friday morning here, but I was at least able to get it to work by using JavaScript to target the elements and add the classes.

    Thank you both again for the great information, this will be very helpful for the future!

  9. #9
    "Certified" Alphaholic
    Real Name
    Rich Fulham
    Join Date
    May 2011
    Location
    Portland, OR
    Posts
    1,002

    Default Re: Accessing {dialog.ComponentName} onInitializeComplete

    Cameron,
    Do the buttons in your CSS Grid layout look okay? Don't they have missing corners and sides? Alpha's default styles assume that a Button List will have three styles of frames: 1) a First button frame, 2) all the middle button frames, and 3) the last button frame.

    I'm trying to figure out if a "sub theme" can be used to solve the problem. Otherwise, I wanted to mention a previous newsgroup post about the issue of multi-line ButtonLists using things like "wrap: pre-wrap" and float's and clear's:

    https://forum.alphasoftware.com/show...-list-question

    -Rich

  10. #10
    "Certified" Alphaholic
    Real Name
    Rich Fulham
    Join Date
    May 2011
    Location
    Portland, OR
    Posts
    1,002

    Default Re: Accessing {dialog.ComponentName} onInitializeComplete

    There are at least two other ways to accomplish a multi-line ButtonList without using JavaScript!

    1) Sub-themes
    2) CSS Tweaks (Only works with SASS themes like iOS7, Alpha, Android)

    I've tested these methods (and supplied a sample workspace) under Build 5581.

    Method 1 keeps everything within the UX.
    Method 2 stores the CSS Tweaks outside of the UX, which makes it easer to share between UX's.

    subThemed-ButtonList.pngTweaked-ButtonList.png

    ButtonLists.zip

Similar Threads

  1. How can I get the ComponentName of the parent object?
    By frankbicknell in forum Application Server Version 11 - Web/Browser Applications
    Replies: 8
    Last Post: 01-09-2013, 08:26 AM
  2. {dialog.{dialog.ComponentName}} how do you find the value of ComponentName?
    By peteconway in forum Application Server Version 11 - Web/Browser Applications
    Replies: 0
    Last Post: 04-16-2012, 02:00 AM
  3. Where do i find help on {dialog.componentname} ?
    By WindForce in forum Application Server Version 11 - Web/Browser Applications
    Replies: 5
    Last Post: 03-22-2012, 11:34 AM
  4. Re accessing define button dialog
    By Portal 6 in forum Alpha Five Version 10 - Desktop Applications
    Replies: 2
    Last Post: 09-09-2010, 12:00 PM
  5. Detailview not showing when componentname > 15
    By rleunis in forum Web Application Server v7
    Replies: 1
    Last Post: 06-13-2006, 04:08 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •