Why is not Label <label> ?

thread: 6 messages  |  last: about 4 years ago  |  started: sunday, february 12, 2006, 7:41 am pst


#1  |  Martin Kronstad (Mjoendalen) Norway Qcodo Core Contributor
Sunday, February 12, 2006, 7:41 AM PST

Why not use the <label> tag for label, instead of <span>?

When using <label> users can click on the text in the label and the control gets focus. This is a great functionality for users using the app.

You would need to pass the label a ref to the control for the label, in order to use the parameter.

#2  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Monday, February 13, 2006, 2:14 PM PST

Martin,

I believe the <span> you are talking about is in the QControl custom class in includes/qform/qform_objects/QControl.inc (as opposed to the QControlBase class).

You should feel free to override the QControl custom class to however you want your items displayed.

Thanks!

#3  |  Martin Kronstad (Mjoendalen) Norway Qcodo Core Contributor
Tuesday, February 14, 2006, 3:10 AM PST

It's not in QControl.inc but it QLabel.inc

protected function GetControlHtml() {
   $strStyle = $this->GetStyleAttributes();
   if ($strStyle)
       $strStyle = sprintf('style=“%s”', $strStyle);

   $strToReturn = sprintf('<span id=“%s” %s%s>%s</span>',
       $this->strControlId,
       $this->GetAttributes(),
       $strStyle,
       $this->strText);

   return $strToReturn;
}

this would need to be changed to something like this:

protected function GetControlHtml() {
   $strStyle = $this->GetStyleAttributes();
   if ($strStyle)
       $strStyle = sprintf('style=“%s”', $strStyle);

   $strToReturn = sprintf('<label for=“%s” id=“%s” %s%s>%s</label>',
       $this->strForControlId,
       $this->strControlId,
       $this->GetAttributes(),
       $strStyle,
       $this->strText);

   return $strToReturn;
}

This would be a “correct” label control. the $this->strForControlId would need to be set when creating a new label ex. $lblMyLabel = new QLabel($txtText->ControlId);

You would ofcource need to set the $this->strForControlId in the _contstruct.

I could make my own QCustomLabel.inc, but I think this would add some good functionality for people that at used to using desktopapplications.

#4  |  Mike Ho (San Diego, CA) United States of America Qcodo Administrator
Tuesday, February 14, 2006, 11:25 AM PST

Ah... I see what you're saying now.

You bring up a good point.

The term “Label” was actually 'borrowed' =) from our friends at Microsoft w/ ASP.NET.  ASP.NET offers two controls, one is “Label” and one is “Panel” -- which is basically a <SPAN> and a <DIV>, respectively.

The reason why they did that was to try and map an HTML webpage back to desktop application constructs (e.g. the Win32 GUI API has concepts of Labels and Panels).

So a QLabel was actually meant to be a <SPAN>.

And I think there is still a need for the QLabel control, as is currently designed in Qcodo.  And we'll soon be adding the QPanel control, as well.  It might have made sense to change the names to QSpan and QDiv - and I've thought about doing it, too - but I think especially b/c a lot of people are starting to get accustomed to MS naming conventions for Web Controls (e.g. label, datagrid, etc.), and with other frameworks using the same naming standard, it might make more sense, for consistency sake, to keep with QLabel and QPanel.  And besides, I want to try and minimize breaking BC from this point forward.

I do think there is also a need for what you're suggesting -- perhaps it should be a QControlLabel?

I dunno... thoguhts?

#5  |  Martin Kronstad (Mjoendalen) Norway Qcodo Core Contributor
Tuesday, February 14, 2006, 11:33 AM PST

Sure, it makes sense maintaining BC and using the current naming conventions. Calling it QControlLabel would make sense since it describes that this is a label that requires a control.

#6  |  owens2024 (Dallas, TX) United States of America
Friday, October 26, 2007, 9:29 AM PDT

Umm... maybe I'm missing something, but how do you do this in the QCodo 0.3.32?  What I want to do is have it output <label> for the name of the control instead of <span> when the control is rendered...

Nevermind figured it out... but for the benefit of others, if want to change your form labels to <label> tags instead of spans you need to edit QControl.class.php under includes/qcodo/qform and make a change around line 53

Replace:

$strToReturn = sprintf('<span class="%s">%s</span><br/>%s%s%s',
    $strClass,
    $strName,
    $this->strHtmlBefore,
    $this->GetControlHtml(),
    $this->strHtmlAfter);

With this:

$strToReturn = sprintf('<label for="%s" class="%s">%s</label><br/>%s%s%s',
        $this->strControlId,
        $strClass,
    $strName,
        $this->strHtmlBefore,
    $this->GetControlHtml(),
        $this->strHtmlAfter);
.bc


Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.