cb2004 Posted February 23, 2016 Share Posted February 23, 2016 Can anybody offer up any tips for this? Basically on a contact form there are certain services, and certain staff members are assigned to those services. When a service is selected in a dropdown, I only want the staff members assigned to that service to be displayed in another dropdown. Guessing it is venturing into Ajax which I have not done with ProcessWire yet. Cheers. Link to comment Share on other sites More sharing options...
cb2004 Posted February 23, 2016 Author Share Posted February 23, 2016 So in my form I am selecting the services: foreach ($pages->get(1040)->children as $child) { $service .= '<option value="' . $child->id . '">' . $child->title . '</option>'; } This is then returning a nice set of options to interrogate from ID: <select name="service" id="service"> <option value="1041">Service 1</option> <option value="1042">Service 2</option> </select> So I am thinking next step is to put a PHP file on the server which would do a $pages->find("template=service, page_staff=VALUE") using Ajax and return the results with the staff name? Link to comment Share on other sites More sharing options...
bernhard Posted February 24, 2016 Share Posted February 24, 2016 How many entries do you have for both fields? Maybe some jquery is easier than ajax.. 1 Link to comment Share on other sites More sharing options...
cb2004 Posted February 24, 2016 Author Share Posted February 24, 2016 Yes I thought that as well. So I am giving each option in the staff dropdown classes: <option value="Staff member" class="1041 1045 1046 1048">Staff member</option> Then if the service dropdown selected is value="1041", only those staff members will be selected. Just got to work on the jQuery and then all done. Link to comment Share on other sites More sharing options...
tpr Posted February 24, 2016 Share Posted February 24, 2016 Classes starting with digits are invalid, better to use "id-1041" for example. But I would use data attributes instead (data-ids="1041 1046", etc). Link to comment Share on other sites More sharing options...
cb2004 Posted February 24, 2016 Author Share Posted February 24, 2016 Yeah, I have been caught out with classes starting with digits a few times. I will look into adding a data tag as you suggest. Cheers. Link to comment Share on other sites More sharing options...
adrian Posted February 24, 2016 Share Posted February 24, 2016 Admittedly I don't fully understand your needs, but PW has some inbuilt support for this if you are using Page fields. You can do something like this: parent=page.service for the page field's "define selector to find pages". This will create an ajaxified UI for field relations. It may not work for what you need, but thought I'd mention it just in case. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now