Problems, need help? Have a tip or advice? Post it here.
12 posts Page 1 of 2
I have a dropdown (front-end) where I collect some cloned pages. Whenever a page is selected I would like to show a second dropdown with info from related pages of the selected page, if that makes sense. But is there a way to do this or isn't this possible with couch?
Hi,
or isn't this possible with couch?
It actually has little to do with Couch.
The trick is to have the first dropdown make an AJAX call to the server with the selected page's ID.
The URL being called (a Couch managed template) can then output the pages related to the submitted page. This returned value of the AJAX call then updates the second dropdown.

I'll assume that the AJAX part, being front-end related, would be trivial for you.
You just need to create a Couch template that accepts the page ID and returns back the selected pages.

Hope it helps.
That would make sense. I want to get the related pages to filter the available places, which would be possible with the solution you suggested, but what if a second user picks a place in between the time the form was shown and submitted by the first user? That would imply a duplicate entry. I can't add a validator to check for unique values since the combination of the id of the related page (activity) and the placenumber are unique, not the placenumber itself.
Not sure if I understood the situation completely, @cowgirl.
Is it that you'd be 'creating' new pages on the basis of the selection?

If so, then the way web-applications work, you'll have to validate things before creating a page as the scenario you mentioned could indeed be possible.
I'll try to explain.
I have events. Each event contains multiple activities.
These activities have a set number of available "places". The places are indicated from 1 to the maximum available places.
So the activity has an editable region of type integer with the maximum amount of available places.

I don't want to make all the places up front since the only property attached to a place is a number, and places can go up to 100 or more. So I want to make a loop counting from 1 to max places.

Then I have a form for each event where people can subscribe for a certain activity and pick a number.
First dropdown, the user needs to select the activity, next I have to get the max_places of that activity to make my second dropdown and I need to disable or remove the places from that dropdown that are already chosen by someone else. So subscriptions that have the same activity-relation, should be checked and filtered (I think I can manage this by looping through).

Up till here I could probably do this with the AJAX/couch template, I guess, even though I still have to figure it out how exactly.

But then my next concern is:
User1 opens the form, selects activity1 and sees a dropdown where place 80 is still free.
User2 opens the form, also selects activity1 and also sees that a dropdown where place 80 is still free, because user1 hasn't submitted the form yet at this point.
Then user2 submits activity1 and place 80, so a cloned page is created with the values activity1 and place 80. Then User1 also submits the form with also activity1 and place 80, because when he was filling out the form, he didn't refesh, so place 80 was still clickable in the form. Result: User1 and User2 both have a cloned page with activity1 and place 80. That would be a problem. So how can I make sure that the combination of activity and placenumber is unique. Not just placenumber, because activity2 can also have a place 80, so placenumber alone isn't unique but the combination activity + placenumber is.
Thanks for the explanation. I get it now.

So, as I was expecting, you are creating pages taking submitted values from the dropdowns.
That, as I mentioned, would require a validator to check if a page with the same values does not already exist before creating a new one.

Incidentally, I just posted a solution that makes use of such a validator -
viewtopic.php?p=21858#p21858

The validator in the post above would need some tweaking before we can use if for your particular use-case. However, before we go down that path I think there is an existing solution that you should perhaps also consider -

Whenever Couch creates a page, and an explicit value for 'k_page_name' is supplied, it always checks if another page with the same name does not exist (if 'k_page_name' is not supplied, Couch uses an automatically created non-duplicate name).

So what we can do is while creating the cloned-page, use the submitted 'activity' and 'place' values to craft k_page_name value (e.g. 'activity1-80'). This way if another person happens to submit the same values, it would be rejected and an error reported prompting her to choose new values.

If that seems like a reasonable solution, please try implementing it.
Else let me know and we'll create the custom validator.

Thanks.
If I would be able to "catch" the error front-end and return a nice message like "Place you tried to register is already taken" or something like that, would be perfect!
If I would be able to "catch" the error front-end and return a nice message
Not a problem. Place a <cms:dump /> in the k_error block to see what variables you need to use.
Is it possible to make an editable region of type relation "required" front-end and back-end?
The usual parameter required='1' applies to type 'relation' editable regions too.

No difference between frontend and backend - what you see in the backend is exactly what gets displayed on the frontend when used in a databound manner.
12 posts Page 1 of 2