Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabularInput with kartik select2 ajax loading #311

Open
ahmadfadlydziljalal opened this issue Aug 26, 2019 · 3 comments
Open

TabularInput with kartik select2 ajax loading #311

ahmadfadlydziljalal opened this issue Aug 26, 2019 · 3 comments

Comments

@ahmadfadlydziljalal
Copy link

Previously thanks for this cool plugin.
How to do 'initValueText' on Mr. Karthik's Select2 for Tabular Input.

If we look at these select2, it provides information to search by that model, not models.

`

  <?php try {
	$url = Url::to(['stock-in/find-stock-in-as-list']);
	
	// Get the initValueText ??? // Problem
	$cityDesc = empty($model->stock_in_id) ? '' : StockIn::findOne($model->stock_in_id)->description;
	
	echo TabularInput::widget([
		'id' => 'some-id',
		'models' => $models,
		/* lot of configuration */
		'columns' => [
			[
				'name' => 'transaction_type_id',
				'title' => 'Type',
				'enableError' => true,
				'type' => Select2::className(),
				'options' => [
					'data' => $tt,
				]
			],
			[
				'name' => 'stock_in_id',
				'title' => $models[0]->getAttributeLabel('stock_in_id'),
				'enableError' => true,
				'type' => Select2::className(),
				'options' => [
					'initValueText' => ???, // set the initial display text
					'options' => ['placeholder' => 'Search for a stock in ...'],
					'pluginOptions' => [
						'allowClear' => true,
						'minimumInputLength' => 3,
						'language' => [
							'errorLoading' => new JsExpression("function () { return 'Waiting for results...'; }"),
						],
						'ajax' => [
							'url' => $url,
							'dataType' => 'json',
							'data' => new JsExpression('function(params) { return {q:params.term}; }')
						],
						'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
						'templateResult' => new JsExpression('function(city) { return city.text; }'),
						'templateSelection' => new JsExpression('function (city) { return city.text; }'),
					],
				]
			],
		],
	]);
} catch (Exception $e) {
	echo $e->getMessage() . ' <pre>' . VarDumper::dumpAsString($e->getTraceAsString()) . ' </pre>';
} ?>

`

Thank you a lot.

@jrguevara
Copy link

Try this:

[
'name' => 'stock_in_id',
'title' => $models[0]->getAttributeLabel('stock_in_id'),
'type' => Select2::class,
'options' => [
'initValueText' => ArrayHelper::map(Stock::find()->all(), 'stock_in_id', 'name'),
//'options' => ['placeholder' => 'Search for a stock in ...],
],
]

@unclead
Copy link
Owner

unclead commented Jun 26, 2021

@ahmadfadlydziljalal I decided to sort out the old issues, so is this issue still relevant or I can just close it?

@jrguevara
Copy link

@ahmadfadlydziljalal I decided to sort out the old issues, so is this issue still relevant or I can just close it?

If you can solved, it will be great! Thks for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants