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

Strange issue - Fixed #116

Closed
lenamtl opened this issue Apr 30, 2020 · 7 comments
Closed

Strange issue - Fixed #116

lenamtl opened this issue Apr 30, 2020 · 7 comments

Comments

@lenamtl
Copy link

lenamtl commented Apr 30, 2020

Hi,

I have a big issue...
If I select checkboxes and refresh the page = the checkboxes get deselected = OK

If I select checkboxes and go to another the page, and click back from the browser
= the checkboxes are still selected = Not OK

I have checked my localstorage and there are no localstorage for the Selection...
So how come these are still selected?
If I refresh the page there are no more selected checkbox, I'm pulling my hair with this, any clue?

Here is my Datatables settings

"stateSave": true,
{									
				
	"targets": 1,
	"visible": true,
	"searchable": false,
	"orderable": false,
	"checkboxes": {
			"selectRow": true,
			"stateSave": false, 
        }
},

"select": {
	'style': 'multi',
	'selector': 'td:nth-child(2)',
},
@lenamtl
Copy link
Author

lenamtl commented Apr 30, 2020

Hi,

I have fixed this way for now

JS

// refresh
if(performance.navigation.type == 2){
location.reload(true);
}

The 2 indicates the page was accessed by navigation into the history.

@lenamtl lenamtl closed this as completed Apr 30, 2020
@mpryvkin
Copy link
Member

Can you provide an URL or an example demonstrating the issue?

@lenamtl
Copy link
Author

lenamtl commented May 5, 2020

After investigations, it was an autocomplete issue
like we often see in a form but I didn't thought that could happens to a table :)

Here is the code fix:

initComplete: function (row) {
    $('th.dt-checkboxes-cell').find('input').attr('autocomplete', 'off');
    $('th.dt-checkboxes-select-all').find('input').attr('autocomplete', 'off');
    $('.dt-checkboxes').attr('autocomplete', 'off');
    },

@lenamtl lenamtl changed the title Strange issue Strange issue - Fixed May 5, 2020
@mpryvkin
Copy link
Member

mpryvkin commented May 5, 2020

Thanks for the follow-up and showing the workaround! I might add autocomplete="off" attribute to the checkbox HTML code. However need to research this further.

From MDN page:

Note: The autocomplete attribute also controls whether Firefox will — unlike other browsers — persist the dynamic disabled state and (if applicable) dynamic checkedness of an <input> element, <textarea> element, or entire <form> across page loads. The persistence feature is enabled by default. Setting the value of the autocomplete attribute to off disables this feature. This works even when the autocomplete attribute would normally not apply by virtue of its type. See bug 654072.

@lenamtl
Copy link
Author

lenamtl commented May 6, 2020

To what I have read putting autocomplete="off" to a form tag will work better compare if applied to an input, but in our case it's not a form, so I don't know how reliable it is.

I have tested with Chrome, Opera and Firefox and IE 11 and this is working fine for now.

Forcing the code refresh based on browser historic is another alternative but we can see the checkboxed checked then uncheck (this is fast but we can see it) .

@lenamtl
Copy link
Author

lenamtl commented May 6, 2020

To fix it directly into your plugin code
Let me know if this is ok

if(ctx.aoColumns[i].mRender === null){
                  colOptions['render'] = function(){
                     //return '<input type="checkbox" class="dt-checkboxes">';
		       return '<input type="checkbox" class="dt-checkboxes" autocomplete="off">';
                  };
               }
 //selectAllRender: '<input type="checkbox">'
selectAllRender: '<input type="checkbox" autocomplete="off">'

@mpryvkin
Copy link
Member

mpryvkin commented May 6, 2020

That seems safe, I will apply the change later today. Thank you!

mpryvkin added a commit that referenced this issue May 8, 2020
From [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete) page:
> Note: The `autocomplete` attribute also controls whether Firefox will — unlike other browsers — [persist the dynamic disabled state and (if applicable) dynamic checkedness](https://stackoverflow.com/questions/5985839/bug-with-firefox-disabled-attribute-of-input-not-resetting-when-refreshing) of an `<input>` element, `<textarea>` element, or entire `<form>` across page loads. The persistence feature is enabled by default. Setting the value of the `autocomplete` attribute to `off` disables this feature. This works even when the `autocomplete` attribute would normally not apply by virtue of its type. See [bug 654072](https://bugzilla.mozilla.org/show_bug.cgi?id=654072).
mpryvkin added a commit that referenced this issue May 8, 2020
From MDN page (https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete):
Note: The `autocomplete` attribute also controls whether Firefox will — unlike other browsers — persist the dynamic disabled state and (if applicable) dynamic checkedness of an <input> element, <textarea> element, or entire <form> across page loads. The persistence feature is enabled by default. Setting the value of the `autocomplete` attribute to `off` disables this feature. This works even when the `autocomplete` attribute would normally not apply by virtue of its type. See bug 654072 (https://bugzilla.mozilla.org/show_bug.cgi?id=654072).
mpryvkin added a commit that referenced this issue May 8, 2020
From MDN page (https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete):
Note: The `autocomplete` attribute also controls whether Firefox will — unlike other browsers — persist the dynamic disabled state and (if applicable) dynamic checkedness of an <input> element, <textarea> element, or entire <form> across page loads. The persistence feature is enabled by default. Setting the value of the `autocomplete` attribute to `off` disables this feature. This works even when the `autocomplete` attribute would normally not apply by virtue of its type. See bug 654072 (https://bugzilla.mozilla.org/show_bug.cgi?id=654072).
mpryvkin added a commit that referenced this issue May 8, 2020
From MDN page (https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete):
Note: The `autocomplete` attribute also controls whether Firefox will — unlike other browsers — persist the dynamic disabled state and (if applicable) dynamic checkedness of an <input> element, <textarea> element, or entire <form> across page loads. The persistence feature is enabled by default. Setting the value of the `autocomplete` attribute to `off` disables this feature. This works even when the `autocomplete` attribute would normally not apply by virtue of its type. See bug 654072 (https://bugzilla.mozilla.org/show_bug.cgi?id=654072).
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

2 participants