Build dynamic buttons

Develop and Deploy Cross-Browser Web Apps .

Build dynamic buttons

Postby kevinotton » Fri May 30, 2014 8:49 am

Is it possible to build dynamic buttons in this way or is there a better way?

e.g.
buttonstring = [{"id":"MIDAHS01", "caption":"MIDAHS01" , "itemStyle":"font-size:20px;"},{"id":"MIDAHS02", "caption":"MIDAHS02"} ,{"id":"MIDAHS03", "caption":"MIDAHS03"} ]

then use something like this to build - this does not work?

SPA.ctl_statusbuttons7.setItems(buttonstring);

Thanks
Kevin
kevinotton
 
Posts: 39
Joined: Thu May 15, 2014 8:18 am
Location: Needham Market, Suffolk, UK


Re: Build dynamic buttons

Postby kevinotton » Mon Jun 02, 2014 12:00 pm

Thanks for the prompt reply.

The links do give me a different solution to what I was trying.

I am still unable to get the new button 'onclick' to work using the example. In the example code I have built with an onclick on the button14.

I have attached a screen shot of the code, _button14_onclick simply sends xui.message("14"); but not on the remade button; I have tried with this. and without this.

Apologies if I am being thick.

Thanks
Kevin
Attachments
question.jpg
question.jpg (35.49 KiB) Viewed 5529 times
kevinotton
 
Posts: 39
Joined: Thu May 15, 2014 8:18 am
Location: Needham Market, Suffolk, UK

Re: Build dynamic buttons

Postby support » Tue Jun 03, 2014 12:42 am

It depends on your [this] scope, if there's a _button14_onclick function in your [this] scope, it will work.

Or you can write event code dir:

onClick:function(){xui.message('hi there')}
support
 
Posts: 352
Joined: Sat Apr 27, 2013 9:22 am

Re: Build dynamic buttons

Postby kevinotton » Tue Jun 03, 2014 9:32 am

My modified serialize code form the examples is attached as I still not get it working.

I added an event to serialize 2 that calls _button14_onclick , this gives a xui message output 14 and works fine.

If I then serialize the code it outputs okay to the box with the event code written in.

The Un-serialize button (2nd >>) creates the new button on the right.

Clicking new button does nothing.

Adding 'this.' or 'SPA.' before making the new button does nothing.

In my real code I have skipped the first part of the process above and have a string creating everything. It all works fine apart from the event/click function

Thanks
Kevin
Attachments
serialize.rar
(3.06 KiB) Downloaded 316 times
kevinotton
 
Posts: 39
Joined: Thu May 15, 2014 8:18 am
Location: Needham Market, Suffolk, UK

Re: Build dynamic buttons

Postby support » Wed Jun 04, 2014 1:08 am

You need give the "host" to the unserialized widgets.

javascript code
_button12_onclick:function (profile, e, value) {
this.Block12.removeChildren(null,true);
// unserialize string to control
var nw = _.unserialize(this.Input1.getUIValue());
// reset it's host
nw.setHost(this);
// append it
this.Block12.append(nw);
}
support
 
Posts: 352
Joined: Sat Apr 27, 2013 9:22 am


Return to CrossUI for Web Apps

Who is online

Users browsing this forum: No registered users and 0 guests

cron