Jump to content

Recommended Posts

Posted

Hello,

I had a problem with this part of code:

$field = $modules->get("InputfieldSelect");
$field->label = $el['label-children'];
$field->attr('id+name','children'); //=> this line was a problem
$field->attr("wrapClass", "large-4 columns");
$options = array('0','1','2','3','4','5','6','7','8','9','+10');
foreach($options as $k => $v) {
  $field->addOption($k, $v);
}
$form->append($field);

and later in some loop I had a trouble

foreach( $form->children as $f ) {
...
}

Because I am still learning Processwire maybe it would be nice to have some kind of "List of reserved words".

My mistake was that I didn't give importance about "children" in this part: 

$field->attr('id+name','children'); 

because I was thinking: ok it will create select field with id="children" and name="children"

But that was wrong :)

Regards,

Sasa

  • 7 months later...
Posted

Using your own two or three character prefix (plus _ or -) to name identifiers can be of help no matter what system we use (css, php, js, etc...). This way it is also easy to tell what belongs to your code and what not. It helps in this issue, but also helps others dealing with your code. Sure, the practice of prefixing is not a bulletproof solution, but it is unlikely that one runs into this issue when sticking to it.

  • Like 1

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...