Posted by texas-bronius on January 13, 2011 at 5:21pm
For some reason my module's form's textfield is not obeying the size => 4 I'm asking it to be. Am I overlooking something (again)?
In addition to the whole code below, see the attached screenshot...
<?php
function project_calc_concrete_calculator() {
$form['instructions'] = array(
'#prefix' => '<p>',
'#value' => t('Enter concrete slab dimensions'),
'#suffix' => '</p>',
);
$form['concrete'] = array(
'#type' => 'radios',
'#title' => t('Pick desired concrete'),
'#options' => array(
'1' => t('80lb Bag of Concrete'),
'0.6' => t('80lb Bag of Regular Concrete'),
'0.5' => t('40lb Bag of Concrete'),
),
'#required' => true,
);
$form['length'] = array(
'#type' => 'textfield',
'#title' => t('Length'),
'#field_suffix' => t('feet'),
'#required' => true,
'#size' => 4,
'#weight' => 1,
);
$form['width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#field_suffix' => t('feet'),
'#required' => true,
'#size' => 4,
'#weight' => 2,
);
$form['depth'] = array(
'#type' => 'textfield',
'#title' => t('Depth'),
'#field_suffix' => t('inches'),
'#required' => true,
'#size' => 4,
'#weight' => 3,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Go',
// '#executes_submit_callback' => false,
'#weight' => 10,
);
$form['msg'] = array(
'#prefix' => '<div id="calc-msg">',
'#value' => t('Enter values, and click Go.'),
'#suffix' => '</div>',
'#weight' => 11,
);
return $form;
}
?>
results in
<input type="text" class="form-text required" value="" size="" id="edit-length" name="length" maxlength="128">
Thanks
-Bronius
Attachment | Size |
---|---|
drupal-6-fapi-size-empty.png | 89.61 KB |
Comments
a few suggestions
If i was debugging that i would start by putting the textfields in a form field group instead of have it floating.
"If you have to do a sequence of actions more than twice, they are in the wrong abstraction layer :D" - Learned from drupal
ok that's a potential aesthetic improvement
But is there any change to the functionality? Shouldn't #size be #size no matter where the textfield on which it lies*?
did you ever resolve this?
I just use css to size them. #size doesn't matter ;)
so what it is?
Yes, css of course works to fix this aesthetically, but I'm a developer, and it's more unsettling to me that this isn't working (or rather, as a humble developer, important to me to know what I'm doing wrong) than it is to make it look right :)
Works for me
I copied your code into a block and got the desired results
hmm.. code for code?
Thanks for that validation. Doubly confused, but at least now i know it's possible and that the difference must be in how we are doing something different :)..
Not to be pedantic, but if you copied the code 1:1 why is your html with name="" instead of, for instance, name="length"? (just something that stood out which may provide a clue)
solution?
I have the exact same issue. I have it working just fine on a local installation clone (on wamp), but when I put it on a linux/apache/mysql/php installation it doesn't obey the #size setting.
Did you ever find a solution?
no, never got it working
Hi- No, I never got this working (to my knowledge). Moving on, css will do it. Yes, the FAPI looks correct and should do it, and as you discovered, it seems to work in dev but not remotely. Maybe clear cache and look again?
Good luck
-Bronius