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

No value returned as default ? #170

Closed
badulesia opened this issue May 18, 2013 · 10 comments
Closed

No value returned as default ? #170

badulesia opened this issue May 18, 2013 · 10 comments

Comments

@badulesia
Copy link

Hi.
I post a form containing a selectboxitmenu. I don't click on the selectmenu, expecting it to return the first line as selected one. Nothing is send. I must click, open, select a line in order to have a value returned.

I click on a button to execute this as debug code
form = document.forms['someform']; idx = form.selectmenu.value; alert(idx);
nothing is returned as default. If the selectmenu is opened and clicked a value is returned as expected.

To bypass this, I use :
form = document.forms['someform']; idx = form.selectmenu.value; if (!idx) idx = form.selectmenu.options[0].value; alert(idx);

Notice that the selectedIndex attribute also returns nothing.

The first line of the menu seems not to be returned as default one if the menu is not clicked. Can you check this please ?

PS : the selectmenu has no option set. I add it a class ".boxit" and then simply
$(".boxit").selectBoxIt();'

@ghost ghost assigned gfranko May 19, 2013
@gfranko
Copy link
Owner

gfranko commented May 19, 2013

You should be retrieving the value attribute from the original select box. Here is an example

@gfranko gfranko closed this as completed May 19, 2013
@badulesia
Copy link
Author

Hello.
I didn't think about that solution. It's so simple when reading it. I was sure that a quick and effective way was possible. Sorry for the annoyance.
Thanks.

@badulesia
Copy link
Author

Le 19/05/2013 03:26, Greg Franko a écrit :

You should be retrieving the |value| attribute from the original select
box. Here is an example http://jsbin.com/ojazar/1/edit

Hello.
I've tested the tip you gave. The behavior is not exactly what expected,
and strangely it works for some boxit, and not others, even in the same
form. I'm not able to find the critera : I've tested index with number
or text, same result. I've also tested document.getElementById

example of what works in any case
HTML
......

JS by collecting form name
$('#id_point').val();
if (!id_point) id_point = form.id_point[0].value;

JS by collecting id
id_point = $('#id_point').val();
if (!id_point) id_point =
document.getElementById("id_point").options[0].value;

Hope this can help

@gfranko
Copy link
Owner

gfranko commented May 19, 2013

Could you create a jsbin or jsfiddle showing the issue you are having? The value attribute of the original select box is kept in sync with the SelectBoxIt drop down.

@badulesia
Copy link
Author

Le 20/05/2013 00:40, Greg Franko a écrit :

Could you create a jsbin or jsfiddle showing the issue you are having?
The |value| attribute of the original select box is kept in sync with
the SelectBoxIt drop down.


Sorry no, I don't known how to use these tools.

I understand that what I report is surprising, I don't understand it myself.
I'm coding with php, generating select with always the same function.
Options are send with arrays of index and text. This function works
perfectly with default select, and all previous version of boxit. I've
never worried about default value send by select if no click have been
done. The only thing that changes between my previous coding and present
is that forms are now submited with jquery ajax. But the bug appears
before submitting the form, when I try to collect the boxit value.

I spend too more time on this bug, I still have work to do. As I've
found a workaround I'll use it. I propose you to study the bug and
report the result when my coding will be finished. I estimate about two
weeks. Thank you for your patience.

@badulesia
Copy link
Author

Hello.

I wrote you about a week ago about issue #170 in selectboxit, asking for
some time to do tests. I've done them, and I've found where the issue is.

What bugged me is that some selectboxits worked fine, and not others,
while I used the same code to generate these boxits with php.
I've found the difference: the size attribute in What is the value returned by selectboxit if the menu is not clicked ? e.g. the user wants the first option to be used directly If no size attribute is set, boxit returns the first option value as default: it's the expected behavior. If a size attribute is set, null is returned. To manage size of boxits in my project, I begun to use the size attribute, what I didn't in previous versions. Than the bug appeared, and leads me to create the #170 issue. So there is really an issue, related to the way that the size attribute is managed. Have a look to the test.html joined. click on test, without choosing in boxit : null is returned. delete size='3' from the and re-run, not it works fine.

Can you have a look at this problem ?

By the way I've finished to code my new project, everything works fine,
including selectboxit ... except for the issue !

Thank you.
Badu.

@badulesia
Copy link
Author

Hello.
After some tests, it appears that the issue is related to the size attribute of <select>
Example : <select ..... size='4'> returns null as default value.
but <select .... > returns the first option value as default, as expected.
I've mailed Greg about this.

@gfranko
Copy link
Owner

gfranko commented May 28, 2013

@badulesia It looks like the normal select box behavior does not return a value when a size attribute is set. In the next release, I will support the size attribute by using a custom HTML5 data attribute instead so that the value can still get returned. Is the size attribute necessary for your project?

@badulesia
Copy link
Author

Hello.
The default selectbox does not return a default value when size is set ?
I've used my own example and found that it's true. It's so
stupid. Is this a documented issue ? No clue on this
http://www.w3.org/TR/html401/interact/forms.html#h-17.6
So this is not a selectboxit issue but just a select issue.
One way to bypass the problem will be to set the first option as
selected by default.

The size attribute is important in my case because I use boxits inside a
Jquery UI accordion. I must control the size of the boxit to fit inside
the accordion to avoid scrollbars.

I'm waiting for your next release.
As always, thank you for your answer :)

Badu.

@gfranko gfranko reopened this May 28, 2013
@gfranko
Copy link
Owner

gfranko commented Jun 25, 2013

I just released SelectBoxIt v3.6.0, which removed the size attribute support and replaced it with the data-size attribute. This should fix your issue!

@gfranko gfranko closed this as completed Jun 25, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants