craphunter
craphunter

Reputation: 830

Form text diappears and comeing ab up again

How do I do that in symfony?

http://dorward.me.uk/tmp/label-work/example.html

When I click into the input field username. The text disappears. If I don't enter nothing and click somewhere else the text is comeing up again. How do I do that in symofny in lib/forms/.

Thanks for an advice!

Craphunter

Upvotes: 0

Views: 83

Answers (2)

craphunter
craphunter

Reputation: 981

'input' => new sfWidgetFormInputText(array(), array('size' => '100', 'maxlength' => '255', 'value' => 'Some text', 'onblur' =>"if(this.value == '') { this.value='Some text'}", 'onfocus' =>"if (this.value == 'Some text') {this.value=''}")),

This is much shorter! Be careful that "Some text" is identical!

If you need to pass more, take a look to SetWidgetsHtml in Symfony form: (slide down) http://www.symfony-project.org/forms/1_4/en/01-Form-Creation

Upvotes: 1

Manse
Manse

Reputation: 38147

This isnt symfony - its javascript ... just take a look at the source (uses jQuery)

HTML:

<div class="slim-control">
    <label for="username"> Username </label>
    <input name="username" id="username">
</div>
<div class="slim-control">
    <label for="password"> Password </label>
    <input name="password" id="password" type="password">
</div>

JavaScript:

(function () {
    var nonEmpty = "non-empty";
    var inputs = jQuery('.slim-control input');
    var setLabelStyle = function setLabelStyle () {
        var label = jQuery(this);
        if (label.val().length) {
            label.addClass(nonEmpty);
        } else {
            label.removeClass(nonEmpty);
        }
    };
    inputs.focus(function () {
        jQuery(this).addClass(nonEmpty);
    });
    inputs.blur(setLabelStyle);
    inputs.each(setLabelStyle);
}());

So if you want to do this - you would need to add the javascript to the template (indexSuccess.php) for example - you would probably need to modify the ids / classes to meet your local needs

Updated

You could create the following form - this would match the above form (untested):

$this->form = new sfForm();
$this->form->setWidgets(array(
    'username' => new sfWidgetFormInputText(),
    'password' => new sfWidgetFormInputPassword()
));

Creating forms (indeed all of Symfony) is very well documented here -> http://www.symfony-project.org/gentle-introduction/1_4/en/10-Forms

Upvotes: 2

Related Questions