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

Error tabularEvents #79

Open
girishcp opened this issue Sep 11, 2020 · 19 comments
Open

Error tabularEvents #79

girishcp opened this issue Sep 11, 2020 · 19 comments
Assignees
Labels
bug Something isn't working

Comments

@girishcp
Copy link

girishcp commented Sep 11, 2020

@buttflattery

My widget is working fine but when i am using select2 with the tabularEvents in the "STEP_TYPE_TABULAR" then getting the following error.

Setting unknown property: yii\bootstrap\ActiveField::tabularEvents

here its my code...

$step1 =[

'model' => $mymodel,

//set step type to tabular
'type' => FormWizard::STEP_TYPE_TABULAR,

'fieldConfig' => [		
	'content_support_title' => [
		'widget' => Select2::class,
		'containerOptions' => [
			'class' => 'form-group'
		],
		'options' => [
			'data' => ArrayHelper::map(\backend\modules\smedb\models\domains::find()->limit(50)->all(), 'id', 'expertise', 'domain'),
			'options' => [
				'class' => 'form-control'
			],
			'theme' => Select2::THEME_BOOTSTRAP,
			'pluginOptions' => [
				'allowClear' => true,
				'placeholder' => 'Select domain'
			]
		],

		//set tabular events for select2 fix which doesnot work correctly after cloning
		'tabularEvents' => [

			'beforeClone' => "function(event, params){
				//fix for select2 destroy the plugin

				let element = $(this);
				element.select2('destroy');
			}",
			"afterClone" => "function(event, params){
				//bind select2 again after clone

				let element = $(this);
				let elementId = $(this).attr('id');
				let dataKrajee = eval(element.data('krajee-select2'));
				let dataSelect2Options = element.data('s2-options');
				$.when(element.select2(dataKrajee)).done(initS2Loading(elementId, dataSelect2Options));
			}",
			"afterInsert" => "function(event,params){
				//initialize the options for the select2 after initializing

				let selectElement = $(this).find('.field-shoottag-'+params.rowIndex+'-tag_id > select');
				let dataKrajee = eval(selectElement.data('krajee-select2'));

				//update the dataset attribute to the
				if (typeof selectElement[0].dataset.select2Id !== 'undefined') {

					//get the old dataset which has the old id of the input the select2 is bind to 
					let oldDataSelect2Id = selectElement[0].dataset.select2Id;

					//delete the old dataset
					delete selectElement[0].dataset.select2Id;

					//add the new dataselect pointing to the new id of the cloned element
					let newDataSelect2Id = oldDataSelect2Id.replace(
					/\-([\d]+)\-/,
					'-' + parseInt(params.rowIndex) + '-'
					);

					//add the new dataset with the new cloned input id 
					selectElement[0].dataset.select2Id= newDataSelect2Id;
				}
				selectElement.select2(dataKrajee);
			}"
		]
	]
]


];`
@girishcp
Copy link
Author

@buttflattery did you get a chance to look into this issue.

@buttflattery
Copy link
Owner

buttflattery commented Sep 12, 2020

@girishcp not yet, i am on vacations currently cant reach to my pc have you matched your code with the demos available here https://yii2plugins.omaraslam.com/formwizard/tabular-step you can see the select2 working , but if everything matches with the code there i would have to look into it again once i come back tomorrow evening

@girishcp
Copy link
Author

girishcp commented Sep 12, 2020 via email

@buttflattery
Copy link
Owner

buttflattery commented Sep 12, 2020

@girishcp i will look into it as soon i come back , but i think this was due to a recent update to add missing default options support for the active field , just rty to switch your version in the composer.json to the the following

"buttflattery/yii2-formwizard": "dev-master#7b7942f5555d528cd46c5dbc55de71b076bcfca5",

and run

composer update

and then verify if it works ? i doubt that it will as i allowed to pass all options to the active field and i need to reset any custom option name like tabularEvents when passing on to the active field options, if you can add a fix for it that will be good otherwise you can switch to the above mentioned commit and continue without error , but you wont be able to set all options for the activeField that are added in the latest commit

@girishcp
Copy link
Author

@buttflattery
I have updated the formwizard as suggested but it also starts showing the tabs but having an issue with the add new in the tab. its not showing the select2 dropdown list as you can see in the below screenshot.

image

@girishcp
Copy link
Author

@buttflattery I have updated with the old version "Release V1.6.17" and it start working.

@buttflattery
Copy link
Owner

@girishcp alrigth i will fix it up soon and will update you.

@girishcp
Copy link
Author

@buttflattery Thank you so much.

@buttflattery buttflattery self-assigned this Sep 14, 2020
@buttflattery buttflattery added the bug Something isn't working label Sep 14, 2020
@buttflattery
Copy link
Owner

@girishcp please pull the latest code by running composer update , should be working correctly now. If everything goes fine you can close the issue

@girishcp
Copy link
Author

@buttflattery
Thanks for working on this issue, the issue has been resolved now but found more issue on this widget after the update.

When I am adding one more items in the "STEP_TYPE_TABULAR" form then it's adding the 2 items in one go and when am trying to delete the blank item then it deleting the existing top one.

The delete (cross button) option also stops working.

The same issue with the SELECT2 field, its also stops working.

@buttflattery
Copy link
Owner

hmm strange i tested it though, can you share the exact code you are using? is it the same one above?

@girishcp
Copy link
Author

@buttflattery
yes, I am using the same code as above, this is a problem with all the versions. When we click on the add button to add one more item in our tab then its adding 2 items by default.

@buttflattery
Copy link
Owner

@girishcp alright i am looking into it and will push the fix soon

@girishcp
Copy link
Author

@buttflattery It's been a long time didn't hear anything from you, I hope everything is fine at your end. Did you get time to fix the issue?

@ZulfikriLbs
Copy link

@girishcp , you have to change this code
let selectElement = $(this).find('.field-shoottag-'+params.rowIndex+'-tag_id > select'); to
let selectElement = $(this).find('.field-{your_model_class_name}-'+params.rowIndex+'-{your_field_name} > select');

hope this help.

@girishcp
Copy link
Author

@ZulfikriLbs thanks for this update, do I need to update this code in the latest version of formwidget.

@ZulfikriLbs
Copy link

@girishcp maybe best to use the latest version of formwidget, but i think it's not necessary.

@girishcp
Copy link
Author

@ZulfikriLbs Thank you, actually, I am asking these questions because I have raised several issues on this widget.

@buttflattery
Copy link
Owner

@girishcp sorry for the delays , i havent been able to give time to my personal projects due to the workload currently and still i am not free from the project. I will be getting free in the next week and will start fixing all the issues on the widget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants