Jump to content

Labelling of fields in admin with the method to get their value via the API


adrian
 Share

Recommended Posts

Hi everyone - being new to PW I have had a few struggles working with the API. As an example, I was just trying to figure out how to get the Input field type (ie Checkboxes, Radios, AsmSelect etc) for a field. I couldn't find what I needed in the cheatsheet and was just about to give up and ask here, but it ocurred to me to look at the name of the select field within the admin where you actually choose the Input field type. It is named: "inputfield" which of course means you can simply do: $field->inputfield but I had tried $field->inputfieldtype and $field->InputFieldType which of course don't work.

I think I'll be using this approach a lot for figuring things out from now on, but I though it might actually be helpful to put "inputfield" in parentheses after the title in the admin panel e.g Input field type ($field->inputfield) or something like that - kind of a contextual cheatsheet.

Not sure if others think this would be useful

Link to comment
Share on other sites

It sounds like you've got a good idea here, but I'm not sure that I understand? Are you talking about identifying what delegate inputfield class a Page inputfield uses? The ones you mentioned (checkboxes, radios, asmselect, etc.) fit that description. But I'm not clear about why you want to retrieve that or where you are showing it. It could also be that it's the end of the work day here and all my caffeine has long worn off. :) I might need to come back to this and read again in the morning. 

Link to comment
Share on other sites

Ryan,

Well the reason I was trying to figure out the input field type is because I was generating a front-end form and needed to figure out the type so I knew how to handle it. I was manually iterating over each field so I could do some unit conversions on the values. Anyway, I discovered a much easier way to do this, so no need to figure out the input field type anymore.

Regardless, back to my point - I guess in general I am just wondering if it might be possible to provide more contextual documentation, probably only for superusers, that shows how to access any of the elements via the API, whether it is the type or columnwidth of a field, or the name (rather than just the title) of a field when in page view. Another example would be the field tags (remember I asked about that the other day).

I'm afraid at the moment this is a vague and not well thought through request. Maybe when I have a little more time I'll come up with a list and a plan.

Thanks for listening :)

Link to comment
Share on other sites

We could have a documentation section for this, but the reality is very few people are looking for those items. They aren't part of what one would typically use in developing a site. So we've tried to take the resources we have for processwire.com docs to focus on the more common needs. And then make sure that the less used things (like those you are talking about) are well documented in the code itself, so that you and me, and others digging deeper into the core can find and understand these things when the need comes up. Longer term, as our resources grow, more and more of this will make it into the formal documentation. 

You can always find a field's type by referencing $field->type. That will always produce an instance of a 'Fieldtype' derivative class. Calling $field->type->className(); will literally tell you which one.

You can get an instance of the Inputfield from: $field->getInputfield($page); where $page is the page you want to get the input for. If you don't know what page, then you can just pass it a 'new NullPage()'; Note that calling $field->getInputfield($page); does instantiate the relevant Inputfield module. This means that $config->scripts and $config->styles may be populated with links to scripts/stylesheets used by the Inputfield. Though if you don't specifically use those $config vars, then it doesn't matter. 

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...