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
initValueText does not work #66
Comments
You may need to debug your code and compare with the demos. The latest release of the widget is higher than the versions you have. |
The problem was, that using of 'text' as attribute name is somehow hard coded, i.e. using |
Yes, I have problem too, so how can we customize this? Example: I have only an api to search, but each form I want use attribute 'name' or 'email' ... to display?? |
I solved this issue by using echo $form->field($model, 'creator_id')->widget(Select2::classname(), [
'value' => $model->creator_id,
'initValueText' => isset($model->creator) ? $model->creator->username : null,
'options' => ['placeholder' => 'Search for User...'],
'pluginOptions' => [
'multiple' => false,
'allowClear' => true,
'minimumInputLength' => 2,
'language' => [
'errorLoading' => new JsExpression("function () { return 'Waiting for results...'; }"),
],
'ajax' => [
'url' => \yii\helpers\Url::to(['user/select2']),
'dataType' => 'json',
'data' => new JsExpression('function(params) { return {q:params.term}; }'),
'processResults' => new JsExpression('
function (data, params) {
return {
results: $.map(data, function (item) {
return {
id: item.id,
text: item.username,
};
}),
pagination: false,
};
}
'),
],
'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
'templateResult' => new JsExpression('function(item) { return item.text; }'),
'templateSelection' => new JsExpression('function (item) { return item.text; }'),
],
]); |
try: |
I have the following code in view:
The select2 input works well, however the initial value does not appear. I've debugged
yii2-widget-select2/Select2.php
and I don't see any problem.$this->data
is set correctly to[ id, value]
in line 130 in methodinit
. What can be the problem?Also
$input
in functionrenderInput
seems to be OK:And also the value
525
what does not appear on the screen is submitted, if I sbmit the form.The version of the package was first 2.0.2. 2.0.3 is not propagated to the composer :-(. But I've tried also with 2.0.3, the symptom is the same.
The text was updated successfully, but these errors were encountered: