PHP Classes

how to set id of parent element

Recommend this page to a friend!

      HtmlForm PHP 5  >  All threads  >  how to set id of parent element  >  (Un) Subscribe thread alerts  
Subject:how to set id of parent element
Summary:attributes for master div segment set
Messages:12
Author:w. studer
Date:2013-02-19 09:34:25
Update:2013-02-21 16:51:40
 
  1 - 10   11 - 12  

  1. how to set id of parent element   Reply   Report abuse  
Picture of w. studer w. studer - 2013-02-19 09:34:25
Hi

When I use CustomHtml element and passing a key in GET class, the result look like:
<div id="myKey" class="htmlform_custom tooldata">
my custom html
</div>

When I use e.g. a SELECT element and passing a key in GET class, the result looks like:
<div class="htmlform_row_div">
<div class="htmlform_label_div">
<label for="SETTING">myLabel</label>
</div>
<div class="htmlform_widget_div">
<select id="myKey" ...</select>
</div>
</div>

Is there a possibility to set the key and the class of the master/parent element ?
For example like:
<div id="myMasterKey" class="htmlform_row_div">

Reason is that I have a JQUERY script which show/hide various elements due to button triggers.
If I can set it in a way it fits for all master tags in same way, it makes the JQUERY script much easier ... ;-)

Btw, I have tried to create master <div> tag manually before, but it seems that it is automatically closed by </div> tag by your library ....


My target:
Having 3 blocks of various fields, all belonging to same "Master".
By triggering button 1, block 1 fields should be visible and block 2/3 fields hidden.
Same logic then for button 2/3.

Hope is clear ;-)

Thx
Wolfgang


  2. Re: how to set id of parent element   Reply   Report abuse  
Picture of Sebastian Schlapkohl Sebastian Schlapkohl - 2013-02-19 10:15:19 - In reply to message 1 from w. studer
All those things you want are not possible with the current package, that's all by design :)

The good news: All the effects are still possible. If you use jquery all the better.

First on hiding without css: $('.hideme').closest('.htmlform_row_div').hide(); where hideme is the class of widgets you want to hide initially.

Now on toggling the widgets: $('.hidebutton').click(function(){
$(this).parent('htmlform_custom_div').next('htmlform_row_div').has('.hideme').toggle();
});

No IDs or such needed, just some well placed classes. :)

This is a very exotic case
, but since I'm heavily using jquery myself I planned for such things, that's exactly why there is a custom widget in the first place and why one can inject code into finished forms. The rest is a question of fantasy and selector magic :D

  3. Re: how to set id of parent element   Reply   Report abuse  
Picture of w. studer w. studer - 2013-02-19 10:44:40 - In reply to message 2 from Sebastian Schlapkohl
Always incredible about your fast replies. Thanks always for.

Also thanks for your tips. They are welcome.
However, there is a small dust on this beauty.

Why is the customHtml not wrapped with the "htmlform_row_div" div ?
Because then all items are wrapped the same.

Also maybe there was some missunderstandings. Sorry for.

I have 3 sets of elements, some are fields, some customHtml.
On top of these 3 sets, I have then the 3 buttons to show/hide.

Due to, the single button will show/hide a combination of fields and customHtml, fields only or customHtml only. Depends on the preparation.

Hmmm, will do some tries with fieldsets and allignblocks.

  4. Re: how to set id of parent element   Reply   Report abuse  
Picture of Sebastian Schlapkohl Sebastian Schlapkohl - 2013-02-19 11:50:13 - In reply to message 3 from w. studer
They are not rows, because rows are a logical element of the form (for error marking a whole row e.g.). But the classes and div-structure is chosen with care, so that nearly everthing should be possible with a combination of custom and jquery. I mean, this is a framework for standard forms, but so far I didn't come across a case where I simply could build something I wanted to or where the javascript got horrendous.

  5. Re: how to set id of parent element   Reply   Report abuse  
Picture of w. studer w. studer - 2013-02-20 14:12:35 - In reply to message 4 from Sebastian Schlapkohl
Well, just tried with htmlform test form index.php.

Therein I changed from
> $testFieldSet = FieldSet::get()->setLegend('simple widgets');
to
> $testFieldSet = FieldSet::get("hugo", "karl")->setLegend('simple widgets');

The result I get is
div class="htmlform_cell htmlform_cell_1">
<input type="hidden" value="true" name="form1_sent">
<fieldset id="hugo">
....


So far so good.
This will solve my needs by simply creating one FieldSet per block I need.


However ... I noticed a kind of inconsistency.
When I do a get for an element, the first is the name and the second (if present) the key.
For a fieldset, the fist is interpreted as key and the second is ignored.
But, when reading the API doc, then sometimes it is only the name, sometimes only the id and sometimes both ;-)

Just for my personal interest.
Is there any reason for this ?
Why not taking always both ?
Is there a disadvantage if a div has both name and id ?

Please note that I have no probs with this - it's your baby - !
Just trying to improve my knowledge and thoughts about doing things best.

  6. Re: how to set id of parent element   Reply   Report abuse  
Picture of Sebastian Schlapkohl Sebastian Schlapkohl - 2013-02-20 16:23:16 - In reply to message 5 from w. studer
The answer ist quite simple and has two reasons, one is semantic, the other is syntactic.

A name-Attribute is _not_ a universal attribute in HTML and, in a form, should have one purpose and one purpose only: to identify and put a name to a piece of form-data. So all value-bearing widgets have an obligatory name in their constructors, while all other classes don't have this parameter.

The Id-attribute is very handy, widely used and therefore integrated into the constructors, but it is and has to be optional. Optional parameters always come last in PHP, that's why there seems to be a switch in parameter order.

BTW: FieldSet does not have a second parameter, that's why it's "ignored" :)

  7. Re: how to set id of parent element   Reply   Report abuse  
Picture of w. studer w. studer - 2013-02-20 17:53:01 - In reply to message 6 from Sebastian Schlapkohl
Great, thanks for explanation.

  8. Re: how to set id of parent element   Reply   Report abuse  
Picture of w. studer w. studer - 2013-02-21 16:01:32 - In reply to message 6 from Sebastian Schlapkohl
I'm sorry to come back on this, knowing that I'm a bad guy ....

I wanted to use the insertElementAfter method.
As it is AFTER of an form-element and I wanted to insert it on top as first item, I thought easiest way is to create a CustomHtml element and gave it a name.
Simple, I thought ...

But, I got a runtime error, because there is no "naming" functionality on CustomHtml.
But, inside HtmlForm.FormElement.CustomHtml.class.php there is the function doRender, which generates the
<div'.$this->printName()
string.

Hmmm....

Of course, I can/will use a InputHidden element, but ..... ;-)

Just wondering ....

  9. Re: how to set id of parent element   Reply   Report abuse  
Picture of Sebastian Schlapkohl Sebastian Schlapkohl - 2013-02-21 16:21:12 - In reply to message 8 from w. studer
Yes, the call is in there, but never does anything and seems to be a harmless relic. Like I said: don't use names for anything but form widgets themselves. "Name" is no universal attribute, if you need to identify something, use the id or a class.

InsertElementAfter exists to be able to change the configuration of a form based on a default form according to a certain state, thereby changing it's logical contents. Conditionally adding widgets for example (Users get different types of settings to set based on user level maybe). The method does not exists to construct a form, but merely to change little details on the fly.

In other news: do not use "name" to identify things, because it is named "name", that's not it's purpose. :D

  10. Re: how to set id of parent element   Reply   Report abuse  
Picture of w. studer w. studer - 2013-02-21 16:38:34 - In reply to message 9 from Sebastian Schlapkohl
Hmmm

can I add an element (e.g. the customHtml) to the form and change the value (by PHP) after adding the element on the form but before the doRender ?


I assume not, or at least not for CustomHtml. Right ?

 
  1 - 10   11 - 12