Creating Smart Buttons in Agile Toolkit

Monday, October 17th, 2011|Uncategorized|by Romans

I am working on a project, which features numerous places where it’s possible to select a client from a drop-down. I thought about creating a single class, which will work as a button, but would also contain the logic of actually adding the client through a form in jQuery UI Frame.

As a result, I’ve created a universal “NewEntry” button, which can be added anywhere like this.

->setLabel(‘New Client’)->setModel(‘Client’,array(‘name’));

This produces the following:

  • Button is added next to the field
  • When button is clicked, new dialog is displayed offering to add new client
  • After form is submitted, dialog closes and new client is automatically selected in auto-complete field
  • Works with any model, label and list of visible fields can be customized

Adding New Button Code

This should be as simple as copy-pasting the following code into your lib/Button/NewEntry.php

class Button_NewEntry extends Button {
public $field=null;
public $label=null;
public $model=null;
public $fields=null;
public $form=null;
function setText($t){
return parent::setText($t);
function setModel($m,$fields=null){
throw $this->exception(‘Execute setLabel() before setModel() on this button’);
if($this->owner instanceof Form_Field){
if($_GET[$this->name]==’click’)return $this->dialog();
function dialog(){

See also git repository link for my implementation.


Posted October 25, 20113:06 am

Hey Romans – really like the functionality and will definitely have a use for this. Thanks for sharing.

Posted October 25, 20113:07 am

ha, you’ll like my next post. About to publish.. :)

Posted April 26, 20127:34 pm

If you stumbled on this and want to use it in 4.2:


change to: $m = $form -> update() -> model -> id;


change to: ->atk4_form(‘setFieldValue’,$this->field->short_name,$m)