10 years ago
5
Topic
Hi all,
Normally we have simple select field with pre-defined options: 1,2,3...and for example last option="add new item"
I want my users somehow extend this list with own custom options, what weren't in this list. How can i do this with Seblod?

For example: field (simple select) has been created with several cities. If user can not find a city, I want him to add a new option to this field when he/she has selected option="add new item". Basically, something like on Facebook - when you choose a company or school....

Can somebody give an idea how to do it with seblod? I know about Conditional States , but how to add custom options from the frontend form???



Get a VIP membership
4229 Posts
Kadministrator
10 years ago
1
Level 1
To update select options you need javascript, this can't be done on server side. One way to d it withut javascript is to have select and another text box, both using the same storage, with some validation so that in case text field is used dropdown value is not stored.
10 years ago
0
Level 2
I guess, as I just tried to describe - two separate forms, using filed group (in order to show outstanding form) and meanwhile use conditional states to hide initial fields (in order to disable storage ??). Please correct me, if i'm wrong...I can't really get in how to disable storage ??
...both using the same storage, with some validation so that in case text field is used dropdown value is not stored....
10 years ago
1
Level 1
There is some custom coding required to let this happen. I can't think of a default Seblod method that can make it work.

I would use a dynamic select field that gets populated from a table in the DB.

If you want to have the "Add new item" option within the select field, you will have to use custom jQuery code to append that option and the associated functionality to the select field. You can put that code in the field settings (orange arrow bottom right -> Stuff -> Script(JS)

When a user cannot find their city and chooses that option, an input field appears (custom JQuery code) which saves the new entry to the DB table that populates the select list. The input field can be set up in your site form view as hidden field. you can then unhide it with your custom JS code.

To have a smooth user experience you can use AJAX to save the new city to the DB on the fly and then repopulate the select field.




10 years ago
0
Level 2
Gebeer, thanks for the reply ! the problem is really obvious - I'm like 99.9% of non-professionals, who simply can not distinguish PHP from JS :)


I'm trying to understand a logic, is there any other way in Seblod? FOR EXAMPLE:
  1. create a content type form "add item" with an simple select field art_city which has last option "add own city" (storage standard->article->art_city)
  2. create separate content type form for example "add city" and place here only one input field art_usercity with AJAX validation plugin (check art_city)
  3. create a group field in the form "add item" and call the field from "add city" when user chooses option "add own city" (storage standard->article->art_city)
Will this work? I think no, because user can't add an option into simple select from the frontend ? That's why I guess you proposed dynamic select.
But for dynamic select we need a separate table in Joomla DB, where user can write own values/options. And later we would populate them.

More complicated, I think, is the situation with dynamic select cascade field!

Technically, i need something what let me write in DB a new city for specific region, what belongs to the specified country. Of course, I'm not talking about only country->region->city case, there're many other examples with 3,4,5... cascades. That's why I have an idea about separate field group (separate content type with a submission form). Obviously, user must stay on the same submission form page, without any redirect ! 

I guess, we can try to use the described above method:
  1. same story with two separate forms - create them
  2. user chooses country->region->city >>>> "add new" >>>> then a "conditional state" calls group field & form with (probably) the same cascade structure (???) and input field when "add new" is set during the latest stage
  3. we must be sure that user is going to write in the correct place in DB !! (so, parent_id must be set correctly...for example he wants to add missing city Billings in Montana<-USA but not in Texas<-USA...you understand what I mean). I don't see any option in Seblod which may help....except custom & safe JS.


That's why we need these paid plugins with "add new" feature "from the box", I want to pay for this, but not to have a headache - how to solve this.

If there is a way using existing plugins/fields, I'm kindly ask somebody who has experience to make a video tutorial / screenshots / manual which fields we need to use/buy and how to customize them in order to reach requested effect.






10 years ago
0
Level 1
    same story with two separate forms - create them
Yes, you need two forms if you go that route.

    user chooses country->region->city >>>> "add new" >>>> then a "conditional state" calls group field & form with (probably) the same cascade structure (???) and input field when "add new" is set during the latest stage
Instead of calling group/form field you could call a module field. In the module field you show a module with the form for submission of the new city.

we must be sure that user is going to write in the correct place in DB !! (so, parent_id must be set correctly...for example he wants to add missing city Billings in Montana<-USA but not in Texas<-USA...you understand what I mean). I don't see any option in Seblod which may help....except custom & safe JS.
You could get the parent_id from the cascading select where the user already is in the correct parent when he chooses "add new". Then in your city submit form you could have a hidden field that gets populated with the parent_id through JS and use that field to save the new entry under the correct parent in the DB.

If there is a way using existing plugins/fields, I'm kindly ask somebody who has experience to make a video tutorial / screenshots / manual which fields we need to use/buy and how to customize them in order to reach requested effect.
I think this is going a little beyond the scope of this forum. You may ask for paid support to get help for your special use case. We can give you ideas here but you will need to figure out how you will do it with the tools available. Imagine how much time one would have to spend on creating a tutorial for this special use case.

If you already know or want to learn how to do position overrides, you can place your custom PHP/JS in there and don't have to spend money on plugins.

The Code Pack plugin is very useful for executing custom PHP and JS without the need for position overrides.

There is a Cascade Select Field plugin that might be useful in your case.

Go and browse through the other available plugins and then try to figure out how you could utilize them to reach your goal.
Get a VIP membership