Closed (outdated)
Project:
Drupal core
Version:
7.x-dev
Component:
forms system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
4 Aug 2015 at 13:21 UTC
Updated:
13 Aug 2022 at 18:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
Sriparna Khatua commentedIf user wants to add "text" field then
$element['#attributes']['type'] = 'text';should be text and it is working fine.Comment #2
purushotam.rai commentedRightly noticed, Drupal 7 does not regards 'type' attribute of 'textfield' element and hence there must be some solution for this. The above patch does not works for me.
Comment #3
purushotam.rai commentedComment #4
hgoto commentedThe patch seems to work for me... @purushotam.rai, if possible, could you please provide more explanation or examle of "Drupal 7 does not regards 'type' attribute of 'textfield' element and hence there must be some solution for this. The above patch does not works for me."?
Comment #5
littletiger commented@purushotam.rai : what's the code you used to test this out? could you share?
@hgoto : likewise, for you it works, can you share a code extract (or whole function) to demo in what use case it works for you?
Having the same need and would love to see progress on this and see the patch committed if validated.
Comment #6
purushotam.rai commentedHi @littletiger,
Here goes my patch to solve this issue. It basically respects the type attribute provided using form api for textfield.
Thanks
Comment #7
purushotam.rai commentedComment #10
purushotam.rai commentedComment #11
pashupathi nath gajawada commentedHi,
Please find the updated patch.
Comment #13
purushotam.rai commented@pashupathi
Could you please provide the interdiff.
Comment #14
hgoto commentedThe patch #11 uses bracket syntax for the array, and it seems to be the only difference from the patch #6. I don't understand why this is necessary. The patch #6 is proper one.
Comment #15
purushotam.rai commentedComment #16
michel.g commentedThis will not work properly with text fields because #type is already set to textfield in $variables['element']. (Hence all the tests failing)
What we could do is define something like a #subtype in which we should allow people to add a few already not existing types.
Comment #17
michel.g commentedAdded a fresh patch which should not break the existing tests.
Comment #19
michel.g commentedSeems there is 1 failure (still better than 973 failures) but it has to do with the max length of a "Menu link title" field.
To be investigated.
Comment #20
michel.g commentedThe failure was very silly. The test doesn't expect maxlength to the the last value in the HTML element. (It expects a space behind it)
I could fix it by just reordering some assignments.
This code will work by defining a #subtype when creating a form element:
$form['number_field'] = array(
'#type' => 'textfield',
'#subtype' => 'number',
'#title' => t('Number field'),
'#default_value' => 1,
'#size' => 5,
'#maxlength' => 5,
);
Comment #21
sokru commentedTested & looks good to me.
Comment #22
AusJohn commented#20 worked great for us.
We changed the quantity field in commerce to type=number.
It feels a lot better to use as a potential customer now.
With the patch in #20, created a custom module and put the following in the mymodule.module file:
Sets the quantity input type to number.
We did the condition on existence of field, not form-id as we have multiple add-to-cart forms. Trying to target by form id would be a nightmare.
Comment #23
sokru commentedComment #24
guypaddock commentedNote that the patch file name
allow-custom-input-types-12773594-19.patchcites the wrong issue number; it should be2545318not12773594.Comment #25
adevms commentedChanged the patch name and also added min and max attributes options.
Comment #26
poker10 commentedThanks for the report and patches. I think this is not a bug, but a feature request - D7 currently does not support HTML5 input types. This functionality can be achieved by several ways:
- contrib module (for example this: https://www.drupal.org/project/elements)
- theme_textfield override in your theme
Anyway, if this issue should be considered, minimally two things needs to be added: tests, change record. Thus I am switching status back to Needs work.