How to right-justify a StringGadget?

Just starting out? Need help? Post your questions and find answers here.
IdeasVacuum
Posts: 143
Joined: Tue Feb 25, 2014 1:27 pm

How to right-justify a StringGadget?

Post by IdeasVacuum »

How can a StringGadget() be flagged to be right-justified? Is this native to javascript? There seems to be plenty of right-justified boxes about? ;)

Tried:

Code: Select all

EnableJS
document.getElementById(7).style.textAlign="right";
DisableJS
But get error from Browser Console:

Code: Select all

TypeError: document.getElementById(...) is null
.........It's important that numbers are displayed right-justified
netmaestro
Posts: 7
Joined: Tue Feb 25, 2014 10:31 am

Re: How to right-justify a StringGadget?

Post by netmaestro »

Hint: You can get the correct id of an element by right-clicking it in your browser and select "Inspect Element". I did that and was able to code this, my very first working SpiderBasic program:

Code: Select all

If OpenWindow(0, 0, 0, 322, 205, "StringGadget Flags", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StringGadget(0, 8,  10, 306, 20, "Right Justified StringGadget...")
  EnableJS
  var x = document.getElementById("dijit_form_TextBox_0");
  x.style.textAlign = "right";
  DisableJS
EndIf
It's remarkable how many times I try to use css syntax like "text-align" in js where only "textAlign" will work. Seriously, why they don't harmonize the syntax is beyond me. I have to look up who to send the bill to for all these bruises on my head.
User avatar
eddy
Posts: 124
Joined: Thu Mar 27, 2014 8:34 am

Re: How to right-justify a StringGadget?

Post by eddy »

Code: Select all

Procedure SetStringGadgetStyle(Id,style$,value$)   
  !spider_GadgetID(v_id).gadget.textbox.style[v_style$]=v_value$
EndProcedure

If OpenWindow(0, 0, 0, 322, 205, "StringGadget Flags", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ;right to left
  StringGadget(1, 10,  10, 300, 20, "Right Justified StringGadget...")
  SetStringGadgetStyle(1,"direction","rtl")
  SetStringGadgetStyle(1,"unicode-bidi","bidi-override")
  
  ;align right
  gadgetId=StringGadget(#PB_Any, 10,  40, 300, 20, "Right Justified StringGadget...")
  SetStringGadgetStyle(gadgetId,"text-align","right")
EndIf
Post Reply