Yii2 how to setup form conditional validation for form input


You want to validate one form input based on the result of of the form.

In case I want to make comments to be necessary only if time is larger than 0. 

This can be achieved in the following way.

On Model add validation to public function rules()

‘when’=>function ($model){
return $model->reply_timespent >0;
‘whenClient’=>”function (attribute, value) {
return $(‘#tickets-reply_timespent’).val() > ‘0’;
}”,’message’=>’Comment can\’t be empty when time is set’],
This is taken from your view while doing show source.
Name of form + attribute
then in your view row class are used so the form are inline instead one after another.
field($model, ‘reply_timespent’,[‘addon’=> [‘prepend’=> [‘content’=>’Time:’]]])->dropDownList(array_combine($addTimeFilter,$addTimeFilter))->label(false) ?>
field($model, ‘reply_time_comment’ ,[‘addon’=> [‘prepend’=> [‘content’=>’Time Comments:’]]])->textInput()->label(false) ?>

How to install Ansbile on CentOS/Redhat

This is pretty simple.

  1. Install EPEP first

    sudo apt-get install epel-release

First add EPEL

Extra Packages for Enterprise Linux (or EPEL) is a Fedora Special Interest Group that creates, maintains, and manages a high quality set of additional packages for Enterprise Linux, including, but not limited to, Red Hat Enterprise Linux (RHEL), CentOS and Scientific Linux (SL), Oracle Linux (OL).

EPEL packages are usually based on their Fedora counterparts and will never conflict with or replace packages in the base Enterprise Linux distributions. EPEL uses much of the same infrastructure as Fedora, including buildsystem, bugzilla instance, updates manager, mirror manager and more.

  1. Install Ansible

Ansible is the simplest way to automate apps and IT infrastructure. Application Deployment + Configuration Management + Continuous Delivery

sudo apt-get install ansible

All done!

How to truncate value in yii2 kartik editable option

You possibly use the following in your view

use kartik\grid\GridView;
use kartik\dynagrid\DynaGrid;
use kartik\dynagrid\DynaGridStore;
use kartik\editable\Editable;
use kartik\select2\Select2 ;
use yii\widgets\Pjax;
use kartik\cmenu\ContextMenu;

You will also need use also the one below. This contain truncate function.


So in your view you might have the following under the column definition

‘class’ => ‘kartik\grid\EditableColumn’,
‘editableOptions’=> function ($model) use ($customerFilter) {
return [
‘format’ => ‘link’,
‘asPopover’ => true,
‘displayValueConfig’ => $customerFilter,  //This is where your value is displayed
‘inputType’ => Editable::INPUT_SELECT2,
‘theme’ => ‘krajee’,
‘data’ => $customerFilter,
‘allowClear’ => true,

then do the following:

replace the displayValueConfig with displayValue

//’displayValueConfig’ => $customerFilter,  //This is where your value is

then add necessary things and use your filter array.

This will truncate a value nicely to 30 characters and display all characters on hover.

‘displayValue’ => Html::a(StringHelper::truncate($customerFilter[$model->company_id], 30, $suffix = ‘…’),[‘tickets/view’,’id’ => $model->ticket_id], [

Hope you enjoy it and let me know if you need any more help with this 🙂


How to fix TypeError: jQuery(…).editable is not a function in yii2 kartik editable gridview issue

You could have a problem described below

This has been copied from https://disqus.com/home/discussion/krajee/not_found_404_kartik_439/

I am having a problem with the editable column in a gridview, I was hopingfor a point in the right direction to resolve. When I add a row in a blank grid via ajax, I reload the grid using pjax. On the Pjax reload the editable column comes up as a button and has no events triggered. Firebug reports the following error.

TypeError: jQuery(…).editable is not a function.

On a page reload after adding the first row everything works as expected. Adding a second line to the grid everything works as expected. The problem only occurs when the first row is added and the grid refreshed via pjax.

This can be fixed by loading the assets manually .

Just put this on the top of your view and it will work fine.

use kartik\editable\EditableAsset;


use kartik\editable\EditablePjaxAsset;


use kartik\popover\PopoverXAsset;


I have also reported it kartik here where more info can be found regards this issue.


Have a happy Yii2 programming!


Santander New Design is not perfect as you would expect :)

Santander bank recently introduce a new design of the Internet Banking. It does not take long to find out issues with it already.

The below is example of bad design or lack of Test Driven Development which I manage to discover :). I only hope that the new app/design has been properly tested and does contain bugs allowing smart people to use it in the way Santander would not expect 🙂

You won’t see the issue until you will try to resize the message window in the Send Secure Message Option.

Funny enough once the windows is resized you cannot change the dimension of it. It seems like their responsive design is not that responsive. Perhaps they should follow google practise and allow apps to be tested on some group of people instead of releasing it to the whole world at once.

I am not a User Interface expert or Usability expert as such 😉 but it sounds funny that Santander bank is allowing something like this. I only hope and pray that my million won’t disappear soon from my account because someone forgot to add showBalance(); function and I will end up having a heart attack from it.

I hope again that they Security Team is better than the App Tester Team.

Looks funny and it’s funny so I though I will share 🙂

Have Fun! Well done Santander now you owe me a beer!

santander bad design

santander bad design

How to Open CSV files using iMacro

1. Let’s make it happened.

The below is just an example which will not work for you as I am using it on bespoke system.

‘open 1 tab only type

‘ignore errors. this is to allow proceed with macro even if the ip has already been removed
‘wait 2 second instead of default 6s if errors occurs (to speed up the work also sometimes you need to increase because the web page might not appear in the right time and some steps will be missing)
‘set up datasource (this is where the CSV is)
SET !DATASOURCE bulk_reconfiguring.csv
‘ you need to specify the number of rows
‘set up loop ( this is what will be repeated from 1 row as the loop is setup as 1 next loop is basically a next row)
‘open a device search do some work and repeat with the next row
‘ you can see that the {{!COL1}} is build in variable from iMacro this is where your data from CSV will be.
URL GOTO=http://xx.xx.xx/ABLDevice
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:OSSMeta-filter-form ATTR=ID:edit-submitonce

How to use Javascript with iMacro and find out the end of file in CSV file.

1. Once you recorded your Macro using iMacro you need to change to file to (.js) extension. This will enable you to use javascript code inside to macro to give what you need.

Example of use of JavaScript can be found here on my Github account.


This piece of code will be found at the finish of CSV files so you can iterate over rows in cvs files.

This is very useful with imacro otherwise you need to type in manually how many rows you got in to CSV files.


datasource – this is path to your datasource C://…

Hylas – this can be ignored 🙂

csv_file_name = your csv name which need to be put into Datasource directory.

function count_rows(datasource,hylas,csv_file_name)
 const CRLF = “\r\n”;
 const LF = “\n”;
 var lines = new Array();
 var file_i = imns.FIO.openNode(datasource+hylas+csv_file_name);
 var text = imns.FIO.readTextFile(file_i); // Read file into one string
 // Determine end-of-line marker
 var eol = (text.indexOf(CRLF) == -1) ? LF : CRLF;
 // Split into lines (number of lines) NUMBER OF LINES IN CSV
 lines = text.split(eol);
 eol = lines.length;
 return eol;

SSD Hosting for 5 dollars a month https://www.digitalocean.com/?refcode=71a52388956e