pogidude Posted June 19, 2013 Share Posted June 19, 2013 In my module's install() method, I got this: //add role_permitted_templates $field_templates = new Field(); $field_templates->name = 'role_permitted_templates'; $field_templates->label = 'Templates users with this role may use on pages they can add to'; $field_templates->labelFieldName = 'path'; $field_templates->type = wire('modules')->get('FieldtypeText'); $field_templates->inputfield = 'InputfieldPageName'; $field_templates->description = 'Select the templates that users with this role can use when adding child pages.'; $field_templates->save(); $this->message("Added field 'role_permitted_templates' to the role template."); $fieldgroup = $this->fieldgroups->get('role'); $fieldgroup->add($field_templates); $fieldgroup->save(); Basically, I'd like to show a text field that sanitizes like the page name field (alphanumeric + dashes + underscore only) but my text field works just like a regular text field i.e. accepts spaces Link to comment Share on other sites More sharing options...
ryan Posted June 20, 2013 Share Posted June 20, 2013 There is no FieldtypeName, and FieldtypeText is only going to use InputfieldText (it's not configurable for this particular fieldtype). So what I'd recommend doing us using the 'pattern' property of the field (which is supported by FieldtypeText) to require a name format: $field_templates->pattern = '^[-_.a-z0-9]+$'; If you want it to accept spaces too, then add a space immediately after the 0-9. Link to comment Share on other sites More sharing options...
pogidude Posted June 20, 2013 Author Share Posted June 20, 2013 Thanks Ryan. I'm still trying to get the hang of using the different fields in PW - which Inputfield a Fieldtype can use or something like that. Basically, I'd like to use the text field used for creating page names, which is why I used InputfieldPageName, because of it's sanitizer. So, what you're saying is, there's no way I can use InputfieldPageName in this situation? Link to comment Share on other sites More sharing options...
pogidude Posted June 20, 2013 Author Share Posted June 20, 2013 On a similar though, how do I know which Inputfield a Fieldtype can use? like how $field_addable->type = wire('modules')->get('FieldtypePage'); can use $field_addable->inputfield = 'InputfieldPageListSelectMultiple'; and I'm pretty sure $field_addable->inputfield = 'InputfieldPageListSelect'; Link to comment Share on other sites More sharing options...
WillyC Posted June 20, 2013 Share Posted June 20, 2013 unique is page.feldtype most fieldtype tell what input.they use .not you Link to comment Share on other sites More sharing options...
pogidude Posted June 21, 2013 Author Share Posted June 21, 2013 hi @WillyC, how do these fieldtypes tell what input they use? is what I'm asking.. for example, there's FieldtypeCheckbox, then there's InputfieldCheckbox and InputfieldCheckboxes. Based on my tests, I can use InputfieldCheckbox on FieldtypeCheckbox but not InputfieldCheckboxes. Another example, I want to use InputfieldPageName or InputfieldName, is that possible? appreciate your help. thanks Link to comment Share on other sites More sharing options...
ryan Posted June 22, 2013 Share Posted June 22, 2013 how do these fieldtypes tell what input they use? is what I'm asking.. Fieldtypes have a getInputfield() method that returns the Inputfield needed by that Fieldtype. So what Inputfield a Fieldtype uses is defined by the developer of the Fieldtype, not the user. Though the developer of the Fieldtype can decide that they might make that configurable to a limited set of other Inputfields that are known to be compatible. This is the case with the Page fieldtype, which is compatible with any Inputfield that is derived from InputfieldSelect. But that's kind of an exception, as the vast majority of Fieldtypes are married to a specific Inputfield. Link to comment Share on other sites More sharing options...
Soma Posted June 22, 2013 Share Posted June 22, 2013 If you look at FieldtypePage getInputfield() it's only InputfieldPage. Then in InputfieldPage you see protected static $defaultInputfieldClasses = array( // default options 'InputfieldSelect', 'InputfieldSelectMultiple', 'InputfieldCheckboxes', 'InputfieldRadios', 'InputfieldAsmSelect', 'InputfieldPageListSelect', 'InputfieldPageAutocomplete', ); InputfieldCheckboxes is only for InputfieldPage alternative input. InputfieldCheckbox is only the input for FieldtypeCheckbox. It's a single checkbox input while InputfieldPage can be multiple. It looks like you are mixing a lot of things up, and looking at your module, your "role_permitted_templates". You have a text field with comma separated values but want to use InputfieldPageName for sanitizing like a page name but which will remove ",". This wouldn't work anyway apart from that you can't use InputfieldPageName here. Just stick with a InputfieldText or InputfieldTextarea, to enter templates comma separated or per line. It would be cool to have a ASM select to select templates, but this would only work if you only use the InputfieldPage with a ASM select, and add templates as options with templateid=>templatename. This unfortunately isn't possible when using a real custom field added to a template, it's only for use when adding it through a hook to a fieldset and on saving take the selected option(s) to save it somewhere. 2 Link to comment Share on other sites More sharing options...
pogidude Posted June 22, 2013 Author Share Posted June 22, 2013 per my question: On a similar though, how do I know which Inputfield a Fieldtype can use? ryan and soma's answer is exactly what I needed (soma's answer is more detailed though ) yeah I've mixed things up since I've been trying to make a connection between what inputfields are useable on certain fieldtypes. when I saw that fieldtypePage had multiple alternate inputfields, then I assumed that fieldtypeText had multiple alternates as well - i.e. email, pagename, pagetitle - they're all text fields. anyway, I did end up using just the regular text field and used Sanitizer::names() to sanitize the input to role_permitted_templates field. thank you both. 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