@@ -150,6 +150,12 @@ abstract class BaseColumn extends BaseObject
150
150
*/
151
151
public $ columnOptions = [];
152
152
153
+ /**
154
+ * @var string the template of input for customize view.
155
+ * For example: '<div class="input-group"><span class="input-group-addon"><i class="fas fa-mobile-alt"></i></span>{input}</div>'
156
+ */
157
+ public $ inputTemplate = '{input} ' ;
158
+
153
159
/**
154
160
* @var Model|ActiveRecordInterface|array
155
161
*/
@@ -214,14 +220,19 @@ public function isHiddenInput()
214
220
215
221
/**
216
222
* Prepares the value of column.
217
- *
223
+ * @param array $contextParams the params who passed to closure:
224
+ * string $id the id of input element
225
+ * string $name the name of input element
226
+ * string $indexPlaceholder The index placeholder of multiple input. The {$indexPlaceholder} template will be replace by $index
227
+ * int $index The index of multiple input
228
+ * int $columnIndex The index of current model attributes
218
229
* @return mixed
219
230
*/
220
- protected function prepareValue ()
231
+ protected function prepareValue ($ contextParams = [] )
221
232
{
222
233
$ data = $ this ->getModel ();
223
234
if ($ this ->value instanceof \Closure) {
224
- $ value = call_user_func ($ this ->value , $ data );
235
+ $ value = call_user_func ($ this ->value , $ data, $ contextParams );
225
236
} else {
226
237
$ value = null ;
227
238
if ($ data instanceof ActiveRecordInterface ) {
@@ -284,11 +295,18 @@ private function normalize($name) {
284
295
/**
285
296
* Renders the input.
286
297
*
287
- * @param string $name the name of the input
288
- * @param array $options the HTML options of input
298
+ * @param string $name the name of the input
299
+ * @param array $options the HTML options of input
300
+ * @param array $contextParams the params who passed to closure:
301
+ * string $id the id of input element
302
+ * string $name the name of input element
303
+ * string $indexPlaceholder The index placeholder of multiple input. The {$indexPlaceholder} template will be replace by $index
304
+ * int $index The index of multiple input
305
+ * int $columnIndex The index of current model attributes
289
306
* @return string
307
+ * @throws InvalidConfigException
290
308
*/
291
- public function renderInput ($ name , $ options )
309
+ public function renderInput ($ name , $ options, $ contextParams = [] )
292
310
{
293
311
if ($ this ->options instanceof \Closure) {
294
312
$ optionsExt = call_user_func ($ this ->options , $ this ->getModel ());
@@ -301,7 +319,7 @@ public function renderInput($name, $options)
301
319
302
320
$ value = null ;
303
321
if ($ this ->type !== self ::TYPE_DRAGCOLUMN ) {
304
- $ value = $ this ->prepareValue ();
322
+ $ value = $ this ->prepareValue ($ contextParams );
305
323
}
306
324
307
325
if (isset ($ options ['items ' ])) {
@@ -314,7 +332,7 @@ public function renderInput($name, $options)
314
332
$ input = $ this ->renderDefault ($ name , $ value , $ options );
315
333
}
316
334
317
- return $ input ;
335
+ return strtr ( $ this -> inputTemplate , [ ' { input} ' => $ input ]) ;
318
336
}
319
337
320
338
0 commit comments