Jump to content

Selected Item Of the UniCheckComboBox


ThiagoFiorilli

Recommended Posts

3 hours ago, ThiagoFiorilli said:

This is doubt of many friends and mine too. The demo is very simple, it doesn't help.

Exactly what are you talking about?

3 hours ago, ThiagoFiorilli said:

Anyway, how to get the text of the selected item.

What do you mean? Explain in more detail.

Link to comment
Share on other sites

6 hours ago, Sherzod said:

Exactly what are you talking about?

What do you mean? Explain in more detail.

Example: I added in the list:

All; A, B, C

If checked "All", then check all items, if uncheck "All" then uncheck all items. 

That way, if I know that the clicked item was "All", then I can do what I need...

 

Link to comment
Share on other sites

This is how I would do it

// OnSelect Event
procedure TMainForm.UniCheckComboBox1Select(Sender: TObject);
var
  s: String;
  i: Integer;
begin
  s:= '';
  for i:= 0 to (Sender as TUniCheckComboBox).Items.Count-1 do begin
    if (Sender as TUniCheckComboBox).Selected[i] = True then begin
      s:= s + IntToStr(i)+': '+(Sender as TUniCheckComboBox).Items[i]+#10;
    end;
  end;
  ShowMessage(s);
end;

 

Link to comment
Share on other sites

@ThiagoFiorilli @picyka

Can you please test this approach?

1. UniCheckComboBox1.ClientEvents.ExtEvents ->

function afterrender(sender, eOpts) 
{
    var me = sender;
    var _insertCheckbox = function() {
        var _id = me.getPicker().id;
        Ext.DomHelper.insertFirst(_id, {
            tag: 'label',
            for: _id + '_allCh',
            html: 'AllCheck/AllUnCheck<hr>'
        });
        Ext.DomHelper.insertFirst(_id, {
            tag: 'input',
            type: 'checkbox',
            id: _id + '_allCh'
        });

        Ext.get(_id + '_allCh').on('change', function(e, combo) {
            ajaxRequest(me, 'allCheckUnCheck', {
                checked: combo.checked.toString()
            });
        });

        me.on('change', function(combo, b) {
            if (combo.getStore().count() == b.length) {
                Ext.get(_id + '_allCh').dom.checked = true
            } else {
                Ext.get(_id + '_allCh').dom.checked = false
            }
        }, {
            delegate: '.x-boundlist-item'
        });

        me.getPicker().un('show', _insertCheckbox);
    };
    me.getPicker().on('show', _insertCheckbox);
}

2. UniCheckComboBox1.OnAjaxEvent ->

procedure TMainForm.UniCheckComboBox1AjaxEvent(Sender: TComponent;
  EventName: string; Params: TUniStrings);
var
  I: Integer;
begin
  if EventName = 'allCheckUnCheck' then
  begin
    if Params.Values['checked'] = 'true' then
    begin
      for I := 0 to (Sender as TUniCheckComboBox).Items.Count-1 do
        (Sender as TUniCheckComboBox).Selected[I] := True;

      (Sender as TUniCheckComboBox).JSInterface.JSCall('fireEvent', ['select', (Sender as TUniCheckComboBox).JSControl]);
    end
    else begin
      (Sender as TUniCheckComboBox).ClearSelection;
    end;

  end;

end;

 

  • Like 1
  • Upvote 1
Link to comment
Share on other sites

On 4/15/2023 at 8:53 PM, Sherzod said:

@ThiagoFiorilli @picyka

Can you please test this approach?

1. UniCheckComboBox1.ClientEvents.ExtEvents ->

function afterrender(sender, eOpts) 
{
    var me = sender;
    var _insertCheckbox = function() {
        var _id = me.getPicker().id;
        Ext.DomHelper.insertFirst(_id, {
            tag: 'label',
            for: _id + '_allCh',
            html: 'AllCheck/AllUnCheck<hr>'
        });
        Ext.DomHelper.insertFirst(_id, {
            tag: 'input',
            type: 'checkbox',
            id: _id + '_allCh'
        });

        Ext.get(_id + '_allCh').on('change', function(e, combo) {
            ajaxRequest(me, 'allCheckUnCheck', {
                checked: combo.checked.toString()
            });
        });

        me.on('change', function(combo, b) {
            if (combo.getStore().count() == b.length) {
                Ext.get(_id + '_allCh').dom.checked = true
            } else {
                Ext.get(_id + '_allCh').dom.checked = false
            }
        }, {
            delegate: '.x-boundlist-item'
        });

        me.getPicker().un('show', _insertCheckbox);
    };
    me.getPicker().on('show', _insertCheckbox);
}

2. UniCheckComboBox1.OnAjaxEvent ->

procedure TMainForm.UniCheckComboBox1AjaxEvent(Sender: TComponent;
  EventName: string; Params: TUniStrings);
var
  I: Integer;
begin
  if EventName = 'allCheckUnCheck' then
  begin
    if Params.Values['checked'] = 'true' then
    begin
      for I := 0 to (Sender as TUniCheckComboBox).Items.Count-1 do
        (Sender as TUniCheckComboBox).Selected[I] := True;

      (Sender as TUniCheckComboBox).JSInterface.JSCall('fireEvent', ['select', (Sender as TUniCheckComboBox).JSControl]);
    end
    else begin
      (Sender as TUniCheckComboBox).ClearSelection;
    end;

  end;

end;

 

Many Thx Sherzod...

  • Thanks 1
Link to comment
Share on other sites

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...