Jump to content

Recommended Posts

Posted

hello all,

In a process module I have a form, and I can't figure out how to set all the options to "checked" for a checkboxes field.

See the "semester" and "year" sections of the code below.

// Form
$form = $this->modules->get("InputfieldForm"); 
$form->id = 'filters';
$form->method = 'get';
$form->action = './';

// Fieldset
$fieldset = $this->modules->get("InputfieldFieldset");
$fieldset->label = "Filters";
$fieldset->icon = "fa-filter";
$fieldset->attr("", "filters");
$fieldset->collapsed = true;

// Course Search
$field = $this->modules->get("InputfieldText");
$field->label = "Search by Course Number or Title";
$field->description = "Start typing a course number or title to filter the list below.";
$field->attr("name+id", "course_search");
$field->columnWidth = 60;
$fieldset->add($field);

// Semester
$field = wire('fields')->get('semester')->getInputfield(wire('page'));
$field->attr("name+id", "semester");
$field->columnWidth = 20;
$fieldset->append($field);

// Year
$field = wire('fields')->get('syllabi_year')->getInputfield(wire('page'));
$field->attr("name+id", "year");
$field->columnWidth = 20;
$fieldset->append($field);

$form->add($fieldset);

The "semester" and "year" fields are page fields output as checkboxes, and when I render the form in my admin page, the fields and all the available options show correctly (see below).

What I'm after is a way to render the form and have all the checkboxes show as checked.

Currently renders like this

post-474-0-75135800-1406228216_thumb.png

What I need

post-474-0-04833800-1406228258_thumb.png

Any help would be appreciated.

Posted

How about:

$field->attr('autocheck', 1);

or:

$field->autocheck = 1;

Or is this for single checkbox only?

Posted

what is the inputfield selctable pages defined with?

$field->attr("value", $field->getSelectablePages(new NullPage));

should work?

  • Like 7
Posted

@arjen

I had hoped it was that easy too — perhaps for a single checkbox field. No luck for this.

@Soma

Bingo!

$field->attr("value", $field->getSelectablePages($page));

Thank you good sir! That was it.

  • Like 1
Posted

EDIT: Looking at all those new posts above (should have checked before I sent my post), it looks like I was not on the same page :)

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
  • Recently Browsing   0 members

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