a-ok Posted October 15, 2014 Share Posted October 15, 2014 Hi folks, As the topic suggests... is there a way to add a parent_id to the dependency field? I managed to find this in the forums https://processwire.com/talk/topic/4323-field-dependencies/?p=56858 which seems to state that @ryan didn't understand why this didn't work. I need to show a field only if the parent_id=1032. Any thoughts? Link to comment Share on other sites More sharing options...
gebeer Posted October 16, 2014 Share Posted October 16, 2014 Do you need this for a frontend form or in the admin? If you are building a frontend form via the API, you could try something like //get page for which to build the form $editpage = $pages->get("template=mytemplate, other selectors"); // just example selectors, they depend on your needs $parentID = $editpage->parentID; // create a new form field (also field wrapper) $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'myform'); // create field only if page parent_id=1032 if ($parentID == 1032) { $field = $modules->get("InputfieldText"); $field->label = "Label"; $field->attr("id+name","myfieldname"); $field->attr("value",$editpage->myfieldname); $form->append($field); } //...other fields If you could explain your use case in more detail, I'm sure we can find a solution that fits your needs. Link to comment Share on other sites More sharing options...
sforsman Posted October 16, 2014 Share Posted October 16, 2014 Hello Richard, Field Depedencies work with Inputfields - parent_id is not an Inputfield for the form. It is a property of the Page-object (which you cannot use). The selector string just looks like a normal selector, but it is not a normal selector. The same syntax is just used here because it feels familiar. 5 Link to comment Share on other sites More sharing options...
a-ok Posted October 16, 2014 Author Share Posted October 16, 2014 Thanks both for your help. I guess since I need to use this in the admin, not as a front-end form, then I cannot show a specific field based on the parent_id/parent? Would be nice to expand this functionality out in the future, as I guess it could become quite useful. Here is my setup... I have a 'News page', with two child pages 'Jobs' and 'Funding'. These child pages act as categories/filters so users can view all news, just jobs, or just funding. Each page within these categories uses the same template, and has a field 'closing_date' and 'attachments' so if the page you are adding has 'Job' as a parent, then it should show these fields... otherwise not. So maybe I just create two templates... but just thought I would try to make it as global as possible. Thanks again R Link to comment Share on other sites More sharing options...
sforsman Posted October 21, 2014 Share Posted October 21, 2014 One of the key design concepts of ProcessWire is that you can use the same fields in multiple templates. Behind the scenes, the values of a field are always stored in the same table (regardless of the template where it is used). This makes it possible to query based on a field without even having to know in which templates it is used. In this respect, it would be completely ok to have multiple templates. Anyway, to answer your question. You cannot currently create a rule that's based on the parent using the default "Show if" -functionality. Now if you want to use the same template, have you considered making the category a Page-field? You could arrange your tree like this News * News item 1 (Category = Jobs) * News item 2 (Category = Jobs) * News item 3 (Category = Funding) Categories * Jobs * Funding The Category-field of the News-template would be a Page-field, that has it's selectable parents set to "Categories". On the frontend you could easily provide filters by listing the pages under "Categories". Implementing the categories this way you can use the built-in "Show if" -feature. 3 Link to comment Share on other sites More sharing options...
a-ok Posted October 21, 2014 Author Share Posted October 21, 2014 Hi @sforsman and thanks very much for this answer. This makes perfect sense and is actually how I structured this before, and the 'Show if' worked. However, I needed to add filters for this, so you could view only Jobs, or only Funding news articles. /news/jobs/ or /news/funding which is why I ended up making each news post a child of those categories. If there's a way to have this /news/jobs/ with them acting as 'categories' then greta but I didn't think this would be possible either. Nonetheless, thanks so much for your explanation and help. Link to comment Share on other sites More sharing options...
sforsman Posted October 21, 2014 Share Posted October 21, 2014 This is not a problem for ProcessWire. There would be multiple ways of implementing that. Check this tutorial for an example https://processwire.com/talk/topic/7548-dual-url-structure-for-categorized-content 1 Link to comment Share on other sites More sharing options...
gebeer Posted October 21, 2014 Share Posted October 21, 2014 I have the exact same scenario and am using page field like sforsman suggested. To make your filters work you can use URL segments. Works like a charm. 2 Link to comment Share on other sites More sharing options...
a-ok Posted October 21, 2014 Author Share Posted October 21, 2014 Thanks to both for your help and answers... wish I could mark both as the solved post Cheers guys! 2 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