wbraganca / yii2-dynamicform

It is widget to yii2 framework to clone form elements in a nested manner, maintaining accessibility.
Other
435 stars 438 forks source link

kartik select2 broken again #121

Open akorinek opened 8 years ago

akorinek commented 8 years ago

The Kartik select2 plugin is not working in dynamicforms. It works when the row is updating, but not when it's cloned or inserted.

TypeError: Cannot read property 'widgetItem' of undefined http://localhost/labdb/assets/cfb9b48e/yii2-dynamic-form.js?v=1454030029:211

<?php echo $form->field($modelSample, "[{$i}]hazards")->widget(Select2::className(), [ 'data' => ArrayHelper::map(Hazard::find()->asArray()->all(),'id','name'), 'options' => ['placeholder' => 'select hazards', 'multiple' => true], 'pluginOptions' => ['allowClear' => true], ]); ?>

I'm using dev-master of yii2-dynamicform and 2.0.7 of kartik/yii2-widget-select2

pigochu commented 8 years ago

me too Uncaught TypeError: Cannot read property 'widgetItem' of undefined

Gujionsen commented 8 years ago

I have this error: Uncaught ReferenceError: initSelect2Loading is not defined

yii2-dynamicform Version 2.0.2 yii2-widget-select2 Version 2.0.7

jmdemoor commented 8 years ago

Anyone been able to code a workaround for this?

akorinek commented 8 years ago

I ditched dynamicform in favour of pjax, much more stable with all widgets. This here is too much of a hack for production use if you need anything more than textinput.

On Feb 9, 2016, at 5:41 PM, J. M. De Moor notifications@github.com wrote:

Anyone been able to code a workaround for this? — Reply to this email directly or view it on GitHub.

jmdemoor commented 8 years ago

That's a shame. Love to see what your view would look like with pjax. It would be a lot of refactoring for me.

leonardojulius commented 8 years ago

I actually Fix the Problem I actually found here at github but i forget what topic is it.. this is what I did. Go to Web->Assest->Folder then Press Controll F find yii2-dynamic-form.js Note not in vendor it should be at the Backend or Front end Folder or where your project save then replace start from line 449 with this code and save

` // "kartik-v/yii2-widget-select2" var $hasSelect2 = $(widgetOptionsRoot.widgetItem).find('[data-krajee-select2]'); if ($hasSelect2.length > 0) { $hasSelect2.each(function() { var id = $(this).attr('id'); var configSelect2 = eval($(this).attr('data-krajee-select2')); $(this).select2('destroy'); $.when($('#' + id).select2(configSelect2)).done(initS2Loading(id));

$('#' + id).on('select2-open', function() { initS2Open(id) });

if ($(this).attr('data-krajee-depdrop')) { $(this).on('depdrop.beforeChange', function(e,i,v) { var configDepdrop = eval($(this).attr('data-krajee-depdrop')); var loadingText = (configDepdrop.loadingText)? configDepdrop.loadingText : 'Loading ...'; $('#' + id).select2('data', {text: loadingText}); }); $(this).on('depdrop.change', function(e,i,v,c) { $('#' + id).select2('val', $('#' + id).val()); }); } }); } };

})(window.jQuery); ` 11111

jmdemoor commented 8 years ago

replace start from line 449 with this code and save

@leonardojulius Thanks for your code. However, my version (2.0.2) of yii2-dynamic-form.js only has 436 lines. When I tried to modify the lines on the matching code for the Select2 widget following your example, I get other errors:

The select2('destroy') method was called on an element that is not using Select2.

Anyway, I think you applied your code to a different version, no?

leonardojulius commented 8 years ago

Download my TextFile and Copy all Code and try temporary replace to see if work, Just back up your old one @Web->Assest->Folder then Press Controll F find yii2-dynamic-form.js Note not in vendor it should be at the Backend or Front end Folder or where your project save Replace all with this code*

Select 2 Js.txt <-- Here

Gujionsen commented 8 years ago

@jmdemoor I have replaced old Select2 function names with new ones (initS2Loading and initS2Open), in yii2-dynamic-form.js and I'm not sure why but after commenting this code $(this).select2('destroy'); finally it worked.

I'm also using yii2-dynamic-form version 2.0.2

jmdemoor commented 8 years ago

@elguja Thanks for the suggestion. I made the changes you did and there is progress. (Someone should probably make a fork so that we don't have to keep messing with the web/assets stuff).

Anyway, When I click the add button on a nested (inner) form, I get 3 new entries instead of just one. (The outer add works fine.) Also, the Select2 is select initialized to whatever the previous Select2 in that table was set. So I am not out of the woods quite yet.

Thanks @leonardojulius and @elguja for sticking this out.

leonardojulius commented 8 years ago

the div maybe the problem, It should be separated

jmdemoor commented 8 years ago

Which div do you mean?

bbod commented 8 years ago

Does anyone know how to modify the 'core' code so we don't have to mess with the assets folder every time there is an update?

Can only contributors modify the code or can one of us do it?

wilsonfalai commented 8 years ago

I have a fork with the fix to work with the newest version of krajee select2

https://github.com/wilsonfalai/yii2-dynamicform

or composer "wilsonfalai/yii2-dynamicform": "dev-master",

fdezdam commented 7 years ago

I had the same problem than @elguja when I changed initS2Loading and initS2Open . I commented $(this).select2('destroy'); and it work for me too.

richard-j-c commented 7 years ago

note, latest version of yii2-widget-select2 no longer uses initS2Open

dariaman commented 7 years ago

@richard-j-c thanks friend, some people said to use select2 v1.0.0 and it works for me when i downgrade the select2 from v2.0.9 to v1.0.0, dynagrid automatic downgrade to v1.4.2

but i don't know sure the latest version of select2 which can use. Thanks for All

uliuli commented 7 years ago

The latest version of select2 that works for me is v2.0.0

luiszg commented 7 years ago

Hello some news for this issue?

I used the @leonardojulius solution and after commenting this code $(this).select2('destroy');

It is working but I want a better solution the wbraganca. dynamic-form was abandoned?

@akorinek commented that is working with pjax somebody have any idea?

moh-mousa commented 6 years ago

@bbod for now you can use assetMap