Skip to content
This repository was archived by the owner on Jul 29, 2022. It is now read-only.

Add sort-option, fix key for selected, and fix double submit#178

Merged
NicolasCARPi merged 7 commits intoNicolasCARPi:experimentalfrom
nathanvda:master
Jun 20, 2018
Merged

Add sort-option, fix key for selected, and fix double submit#178
NicolasCARPi merged 7 commits intoNicolasCARPi:experimentalfrom
nathanvda:master

Conversation

@nathanvda
Copy link
Contributor

@nathanvda nathanvda commented Jun 18, 2018

As mentioned in the the PR default text, I targeted the "experimental" branch!

So maybe this is not ideal, but the first two commits were discussed in #167 (and #176) where I

  • make sure the key is used when setting a selected value
  • make sure the sorting is optional

I set the default option to not-sorted, which may not be your "default" choice. That could easily by changed? I added tests for these two cases.

Furthermore I added a naive approach to prevent double submits. I noticed in my code that every form.submit was called twice. I was not able to get to the real cause of that, but did manage a simple work-around preventing it.

I hope this is useful. If you have any feedback, let me know.

The default option is not-sorted, which is
what it used to be long ago. Not sure what is
preferable.
Not sure what caused it, but somehow the form.submit 
was called twice. This prevents double submits 
in a naive but effective way.
I am leaving the console.warn in there, but we
could just as easily remove it? I know logging to
console could be a problem with IE9-10 (if it is
not opened —WTF) but I prefer to include a console
shim in my own code. And there already is another
in the code.
@nathanvda
Copy link
Contributor Author

Sorry, it got a bit dirty when fixing the codacy reviews. Squash merge it?

Copy link
Owner

@NicolasCARPi NicolasCARPi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, thanks for your contribution. Please see my comments.

Congrats for adding a qunit test ;)

b = b[1];
return a < b ? -1 : (a > b ? 1 : 0);
});
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace (add a plugin to your editor to see them!)

$(option).prop('selected', 'selected');
}
// add the selected prop if it's the same as original or if the key is 'selected'
if (json['selected'] === key || key === $.trim(original.revert)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use dot notation (json.selected)

e.preventDefault();
e.stopPropagation();

if (isSubmitting) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this part. Can you explain here why you added the isSubmitting var?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I explained above: I experienced double submits, form.submit was called twice, and this was my work-around. You do not have to include this if I am the only person experiencing this? I have been experiencing this problem for a long time, but it didn't really bother me (my data was just saved twice) (I noticed this in the logfiles but just ignored it), until I attached a callback and then it became a "visual" problem. I tried making a test-case for it, but I need to find a way how to capture the calling of the ajax-request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear: the user did not do anything strange, just press enter, or click 'Ok' (to start the submit action). It occurs in chrome, ie and firefox. The only thing deviating from the default is I style my buttons using bootstrap, which should not cause it imho?

@NicolasCARPi NicolasCARPi merged commit 3e4d6fa into NicolasCARPi:experimental Jun 20, 2018
@NicolasCARPi
Copy link
Owner

Hello, I have merged your contribution. I renamed the option in lower case to be consistant with the rest. And also removed the console warning.

Thanks :)

@nathanvda
Copy link
Contributor Author

Thanks 👏 👏 and it was my pleasure 👍 👍 😉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants