Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

new mForm.Element.Select(); placeholder problems #1

Closed
mebusvg opened this issue May 31, 2012 · 5 comments
Closed

new mForm.Element.Select(); placeholder problems #1

mebusvg opened this issue May 31, 2012 · 5 comments

Comments

@mebusvg
Copy link

mebusvg commented May 31, 2012

My forms will hide automatically at dom ready and when a Modal windows is initialized the form will be shown correctly (when a form is styled with: display: none; the form won't show correctly, so this is my little fix).

$$('form.mForm,form.mFormAuto').each(function(formelements)
{
formelements.setStyle('display', 'none');
});

Now when a modal window with a form is being initialized there are some JSON requests that will get the data for making the select fields.

The form standard contains the next code:

select name="devicetype" placeholder="Type Apperaat" name="type" title="ajax/AjaxGetDeviceTypes.php" data-required style="width:275px"></select

the new options are injected and with the help of

new mForm.Element.Select({original: selectid, search: false, noSearchResults: 'Geen resultaten', placeholderSearch: 'Zoeken...'});

it will make a nice select with a nice placeholder. But when i want an option be selected as default it wont work and I'll get the next error:

this.select is undefined

this.select.removeClass(className);

so when I remove the attribuut 'placeholder' out of the select element it will create that error. I can't make a fix. So is this a bug? Or is there a temp fix? Version 0.2 also didn't solve it.

@StephanWagner
Copy link
Owner

Ok i think i know whats happening. Are you trying to select an option with this.select(value) (this being the mForm.Select instance)?

Try this.original.select(value);

Its actually an interesting point. I might change it in 0.2.1 that you can use this.select() too, this actually does make sense as you can use it with the original element as well, like $('my_select_field').select(value);
I did it this way because i wanted everything to be handled with the original select field.

Did this help?

@mebusvg
Copy link
Author

mebusvg commented Jun 1, 2012

edit: $(selectid).select(1); did the trick! Thanks.

Don't know for sure if I understand you, but I want the same thing as the first example on this page: http://htmltweaks.com/mForm/Documentation/Element_Select

So that "First Option" is automatic selected. But when you create a ( new mForm.Element.Select() ) select field that gets it data through a JSON request I can't make something like "First Option" to be selected as default.

I'm working on this script: http://mijngamepc.nl/mboxmform/mBox.Advanced.js

here is a template (smarty) file with some forms in it: http://mijngamepc.nl/mboxmform/customers.tpl

Maybe this helps a little bit about what I'm exactly doing with your mBox and mForm plugin and maybe there are some ideas for your plugin? Anyway, with my own plug-in I clone forms so that they can be use multiple times and so there can be a unlimited amount of modal windows.

But if you take a look at the function 'advancedJSONrequest' and then from line 215 you can see how I built my select field. What I just want is that when I click the refresh image at a form that when a option is selected that that option will be shown again and new content loaded with a JSON request is also there. I know how I can make it but I can't make it to work that an option can be selected as default just like 'First Option.

So when a modal window is loaded for the first time an select field can look like this:

select
placeholder
option 1
option 2
option 3
/select

and after I selected as example 'option 2' the select field will look like this:

select
option 2
option 1
option 3
/select

after a modal refresh. But can't make it without a placeholder. And I understand your solution I think, Thanks!

@mebusvg
Copy link
Author

mebusvg commented Jun 1, 2012

Okay, $(selectid).select(1); did the trick. But when a option is selected now and a select field is required the red dot wont go away automatically. Only after I click the the same or another option.

(I'm dutch, so there are some dutch words in my script:P)

@StephanWagner
Copy link
Owner

just updated to 0.2.5
I actually did some work on required elements. Try this version and let me know if it solved the problem.

@mebusvg
Copy link
Author

mebusvg commented Jun 2, 2012

Well, the placeholder issue is solved now, in version 2.5 it isn't a requirement to put in a placeholder anymore and it will select the first option now! Thanks (: Do have another issue but I'll make another page for that. This one can be closed!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants