Jump to content

Clear Button


Aggie85

Recommended Posts

2 hours ago, Aggie85 said:

I would like the Clear button on edits to only show when the edit button has the focus.

How do I achieve this?

Hello,

One possible solution:

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  with UniEdit1 do
  if ClearButton then
  begin
    JSInterface.JSAddListener('focus', 'function(cmp){if (cmp.getValue()!="") cmp.getTrigger("clear").show()}');
    JSInterface.JSAddListener('blur', 'function(cmp){cmp.getTrigger("clear").hide()}');
  end;

end;

 

Link to comment
Share on other sites

2 hours ago, Sherzod said:

Hello,

One possible solution:

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  with UniEdit1 do
  if ClearButton then
  begin
    JSInterface.JSAddListener('focus', 'function(cmp){if (cmp.getValue()!="") cmp.getTrigger("clear").show()}');
    JSInterface.JSAddListener('blur', 'function(cmp){cmp.getTrigger("clear").hide()}');
  end;

end;

 

Where do I put this code? I put it in onCreate but it didn't work

Link to comment
Share on other sites

1 hour ago, eduardosuruagy said:

UniGui Teste.rar 56.64 kB · 1 download

procedure TFormTeste.UniFormCreate(Sender: TObject);
var I: Integer;
begin
  for I := 0 to Self.ComponentCount - 1 do
  begin
    if Self.Components[I].ClassType = TUniEdit then
    begin
      with TUniEdit(Self.Components[I]) do
      begin
        if ClearButton then
        begin
          JSInterface.JSAddListener('afterrender', 'function(cmp){cmp.getTrigger("clear").hide()}'); //<--------
          JSInterface.JSAddListener('focus', 'function(cmp){if (cmp.getValue()!="") cmp.getTrigger("clear").show()}');
          JSInterface.JSAddListener('blur', 'function(cmp){cmp.getTrigger("clear").hide()}');
        end;
      end;
    end;
  end;
end;

 

Link to comment
Share on other sites

On 7/16/2022 at 2:28 PM, Sherzod said:
procedure TFormTeste.UniFormCreate(Sender: TObject);
var I: Integer;
begin
  for I := 0 to Self.ComponentCount - 1 do
  begin
    if Self.Components[I].ClassType = TUniEdit then
    begin
      with TUniEdit(Self.Components[I]) do
      begin
        if ClearButton then
        begin
          JSInterface.JSAddListener('afterrender', 'function(cmp){cmp.getTrigger("clear").hide()}'); //<--------
          JSInterface.JSAddListener('focus', 'function(cmp){if (cmp.getValue()!="") cmp.getTrigger("clear").show()}');
          JSInterface.JSAddListener('blur', 'function(cmp){cmp.getTrigger("clear").hide()}');
        end;
      end;
    end;
  end;
end;

 

it worked thank you very much!

  • Like 1
Link to comment
Share on other sites

  • 4 months later...
On 7/17/2022 at 1:28 AM, Sherzod said:
procedure TFormTeste.UniFormCreate(Sender: TObject);
var I: Integer;
begin
  for I := 0 to Self.ComponentCount - 1 do
  begin
    if Self.Components[I].ClassType = TUniEdit then
    begin
      with TUniEdit(Self.Components[I]) do
      begin
        if ClearButton then
        begin
          JSInterface.JSAddListener('afterrender', 'function(cmp){cmp.getTrigger("clear").hide()}'); //<--------
          JSInterface.JSAddListener('focus', 'function(cmp){if (cmp.getValue()!="") cmp.getTrigger("clear").show()}');
          JSInterface.JSAddListener('blur', 'function(cmp){cmp.getTrigger("clear").hide()}');
        end;
      end;
    end;
  end;
end;

 

Hi @Sherzod,

Good day!

I tried with TUniDBEdit, but the "afterrender" has no effect.. If I move the record from UniDBGrid, the display TUniDBEdit always show the clearbutton.

Any workarround?

Thanks

Frances

Link to comment
Share on other sites

13 minutes ago, fraxzi said:

Any update? :)

Try this approach, added dirtychange event:

procedure TMainForm.UniFormCreate(Sender: TObject);
var I: Integer;
begin
  for I := 0 to Self.ComponentCount - 1 do
  begin
    if Self.Components[I].ClassType = TUniDBEdit then
    begin
      with TUniDBEdit(Self.Components[I]) do
      begin
        if ClearButton then
        begin
          JSInterface.JSAddListener('afterrender', 'function(cmp){cmp.getTrigger("clear").hide()}');
          JSInterface.JSAddListener('focus', 'function(cmp){if (cmp.getValue()!="") cmp.getTrigger("clear").show()}');
          JSInterface.JSAddListener('blur', 'function(cmp){cmp.getTrigger("clear").hide()}');
          JSInterface.JSAddListener('dirtychange', 'function(cmp){cmp.getTrigger("clear").hide()}'); //<--------
        end;
      end;
    end;
  end;
end;

 

Link to comment
Share on other sites

2 hours ago, Sherzod said:

Try this approach, added dirtychange event:

procedure TMainForm.UniFormCreate(Sender: TObject);
var I: Integer;
begin
  for I := 0 to Self.ComponentCount - 1 do
  begin
    if Self.Components[I].ClassType = TUniDBEdit then
    begin
      with TUniDBEdit(Self.Components[I]) do
      begin
        if ClearButton then
        begin
          JSInterface.JSAddListener('afterrender', 'function(cmp){cmp.getTrigger("clear").hide()}');
          JSInterface.JSAddListener('focus', 'function(cmp){if (cmp.getValue()!="") cmp.getTrigger("clear").show()}');
          JSInterface.JSAddListener('blur', 'function(cmp){cmp.getTrigger("clear").hide()}');
          JSInterface.JSAddListener('dirtychange', 'function(cmp){cmp.getTrigger("clear").hide()}'); //<--------
        end;
      end;
    end;
  end;
end;

 

YES!

You're the Man @Sherzod!! "dirtychange" works like a charm. :)

 

Thanks much with your superb support.

-Frances

  • Thanks 1
Link to comment
Share on other sites

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...