来自 https://www.drupal.org/node/320313
When creating a new node there are always 2 empty fields showing up for those multiple values fields.
There is the "add another item" button, so it would be really nice if only one (or none) empty field is showing up.
In 99% case is a good gui design but with flexi-field for exemple the for can be realy big...
I'm think also is a good idea if we can enable the "add another item" button for multiple value with limited number of item
The original request are here http://drupal.org/node/317052 i'm just copy/past the text because i need this feature to.
Comments
#1
jeremy_a CreditFor one field and an "add more" button, i imagine you would set the original value of the CCK field to 1, and add your own "add more" button, then change the field to "multiple values", then redirect back to the page & hide your "add more" button?
Haven't tried it though
The number or fields initially displayed could be a setting on the fields settings form.
By stealing Views' dependent.js, we could even display it only if the 'multiple' setting is 2+
I personally have no intention to work on this in a near future, so patches welcome...
#3
yang_yi_cn CreditI'll try to write a patch for that... Our clients wanted to see only one empty field.
Where to look for?
You'll want to check :
- content_multiple_value_form() in includes/content.node_form.inc
The beginning of the function determines how many widgets to display.
- content_field_edit_form() / content_field_edit_form_submit() in includes/content.admin.inc
Handles the fields settings form. The setting will need to be added below the 'widget' section ('These settings apply only to the %field field as it appears in the %type content type')
I'd suggest leaving out the dependant.js stuff I mentioned in #2 for now.
#5
yang_yi_cn CreditFile | Size |
---|---|
1.7 KB |
Ok, after look into the code I understand the logic behind multiple values fields.
Let me explain it here:
A field have an options to indicate it can have 1, 2, 3,... unlimited values in the settings page.
It interpreters to the value of $field['multiple']
, it can be 0, or 1, or 2,3,... etc. '0' means you set 'the field has 1 value' in the options, thus no multiple values. '1' means unlimited. Any number greater is considered the fixed value of 'the field has x values'.
Now let's look into the situation
switch ($field['multiple']) {
....
case 1: // unlimited
...
(in includes/content.node_form.inc)
The ideas here is always have a extra empty field to let the user input data. So it should show 1 widget when there's no data, 2 widgets(1 filled, 1 empty) if there's 1 data, 3 widgets (2 filled, 1 empty)..., so on.
It works when there are already some data. However here comes the problem when there's no data: the count($items)
is always 1, whether it's no data or 1 data. If there's no data, it's something like
array(
'0' => array('uid' => NULL)
)
, which is set by content_set_empty() .
So, when there's no data, the count is still 1, then plus another emtpy field, it's 2 empty fields.
I've fixed this by set the count correctly when there's no data or 1 data.
The patch is attached.
Sorry, but -1.
Even if that's not clearly apparent in the code comments, providing 2 empty widgets is the *intended* behavior.
+1 for making this an option, defaulting to 2.
#9
yang_yi_cn CreditSo let me make it clear, the wanted behavior will be:
Set an option - 'minimum widgets for unlimited values', defaulting to 2
For unlimited values:
when the field has no data -> show $min widgets,
when the field has 1 data -> show 1 data + 1 empty field,
when the field has x data -> show x data + 1 empty field,
If that's correct, I'll roll another patch.
#11
yang_yi_cn CreditFile | Size |
---|---|
3.18 KB |
made variables per field, which are set in the content_edit_form and can be accessed like:
variable_get('content_minimum_widgets_'. $field_name, '2')
patch attached. (apply against rc10)
#12
yang_yi_cn CreditFile | Size |
---|---|
3.18 KB |
made variables per field, which are set in the content_edit_form and can be accessed like:
variable_get('content_minimum_widgets_'. $field_name, '2')
patch attached. (apply against rc10)
Great ! I'll try to test soon.
Storing this setting in a variable is not right, though. Variables are used for storing various pieces of data for which there is no dedicated table and storage schema.
For fields and field settings, we have those : it's the content_node_field and content_node_field_instance tables.
If the value is stored in $field['widget']['minimum_widgets'] by the time content_field_instance_update($field) is called,
content_field_instance_update() normally takes care of storing this in content_node_field_instance.widget_settings.
Then, later on, the value should be available $field['widget']['minimum_widgets'] when you need it.
Also, I should probably have warned you that we'll probably want to wait until the offcial 2.0 release is out before committing this. We're trying to release shortly now, and I'd prefer not to rush code in.
#14
yang_yi_cn CreditAs we are putting this option in the 'widget' setting instead of 'field' setting, I can't find a way to save it in the content module level, because all the field widget settings seems to be implemented by individual cck field modules.
It's always something like:
$setting_names = module_invoke($field['module'], 'field_settings', 'save', $field);
and the content module itself seems not having any widget settings at all, so it's kind of hard for me to store it in some content related tables.
When you have time to test, can you change the storage of the variable as well?
#15
dopry CreditStatus: | Needs review | » Needs work |
Frankly, I think displaying a single widget is better by default.. I dislike the two extra widgets, especially with the add another option. I'd be down to display only a single widget for empty fields, and no extra widgets once the field is populated as a default. It leaves the UI less cluttered. It seems like a good solution until the appropriate database modifications and ui can be put in place for controlling the number of additional widgets displayed.
@yang_yi_cn: could you move the storage for that setting to the content_field_instance table? I think that would be a big step towards satisfy both yched and myself. and thanks for your first patch. I for one am using it. :)
#16
zilla Credit@dopry - i'm still confused about the original idea (above) to have this show 2 empty by design...that's a very cluttered UI and crowds the node add/edit forms out the wazoo when many cck's are used and many are set to unlimited (or high numbers)
#17
dopry Credit@zilla: Thats just the way it has been.. called legacy and too late to change expected behavior. moving this to a configuration option is ideal so you can choose. Do you have time to update the patch for this setting moving the value to the node_field_instance table?
#18
zilla Crediti don't! i'm totally inept with code so am more than reluctant to commit a patch for a module as significant as this!
#19
heacu Credithi, i think dopry is right in 15 above. the extra field is pointless if you have "add another" right below it. showing two empty fields looks weird to everybody i've showed this too. i'll probably solve this with jquery until it the behavior is parameterized into what, 2.2???
#20
heacu Creditjust as a follow up to the post i just made, i just put this into my javascript, with "elar-processed" being the class i assign to stuff that i've processed already:
Drupal.behaviors.elar = function(context) {
$('table.content-multiple-table').not('.elar-processed').addClass('elar-processed').find('tr:last').hide(); //remove() didn't work so well
}
this seems to work just fine. removing from the DOM with remove(), on the other hand, seems to cause problems in at least some cases.
anyway, offered up to those of you with a personal preference for Javascript workarounds over PHP patches.
Semi-related request : #344587: Enable 'add more' button for non-unlimited fields.(both requests are better dealt with separately, though).
This thread is on my list of things to review / tackle. Karen and I both have little time for the time being, plus our focus is shifting to Fields in D7 core, so this list doesn't move too fast right now...
#24
jannalexx CreditI agree with opinions here, too space for nothing, please consider removing (or have the an option to) the second input instance. Add more is more than enough for me, just a point of view,. is the patch for the stable release? or we are expecting something more sophisticated? thanks
#26
snown CreditSo I successfully used the patch on my site when it was hosted on my local computer. But now that I've moved it to a remote host the option is no longer there and my fields went back to the default of 2.
Any ideas?
#27
snown CreditNevermind, it turns out that somehow the backup of cck got set as the default, and that copy did NOT have the path applied.
all is well with the world again.
#30
phdhiren CreditAt my surprise, with the field having type of filefield and imagefield gives the result as one field displays at a time of node/add
Would be great if other fields are also like that admin setting for this would be a more better option.
#31
esend7881 CreditWill this patch work on 6.x-2.2?
No offense, but displaying 2 fields by default seems more like a bug than a feature. What is the logic behind that?
#32
gagarine CreditCategory: | feature | » bug |
"What is the logic behind that?" Anyway if they have a logic they is not for 80% of user -> http://www.d7ux.org
A made some test with users and one right solution is this one:
- Show one empty field
- Show "add an other buton" to explain you can add more field but rename it in "add an other name of the field"
- When you add an image or files and the user press "upload" add an new field bellow (because you have an action from the user, so you can transform the interface).
After this bug is corrected a good new feature is the possibility to change how many empty field need to be show.
#33
markus_petrux CreditI think this is something that will be affected by #196421: Deleting unwanted multiple values / multiple values delta issues
#34
pribeh Credit- Show one empty field
- Show "add an other buton" to explain you can add more field but rename it in "add an other name of the field"
- When you add an image or files and the user press "upload" add an new field bellow (because you have an action from the user, so you can transform the interface).
bump. I was sent here from the imagefield issue thread. I'm not sure if I should request this in another thread maybe, but I'm simply looking for the same behavior exhibited for a specific value of imagefields as when having set unlimited values of imagefields in the content-type edit form. One imagefield input by default, then others added upon user upload until the (value) limit is reached.
#35
quicksketch CreditCategory: | bug | » feature |
It's not a bug if it's intentional. We're asking for a new feature that hasn't ever existed.
#36
Gyt CreditVersion: | 6.x-2.0-rc10 | » 6.x-2.3 |
Status: | Needs work | » Needs review |
File | Size |
---|---|
1.27 KB |
Simple patch for showing one empty field by default.
#37
pribeh CreditHey Gyt,
Thanks for posting this patch. Patched up content.node_form but it doesn't appear to work on my end. I still get a list of X number input fields. Do I have to recreate my content-type or imagefield to make this work?
#38
Gyt CreditHm, imagefield already has this feature. Try to create new node - one empty field will appear. When you edit node, you "still get a list of X number input fields" + one empty field.
#39
pribeh CreditImagefield apparently doesn't have anything to do with this - I was sent here from there having requested this feature. I've attempt to create a new node and still get a list of X (6 set right now) number of empty inputs fields.
#40
Mark Theunissen CreditWould like to see this feature implemented, don't care which way is the default but having two empty fields is something our users are confused by! +1 subscribing.
#43
Nick Lewis CreditStatus: | Needs review | » Needs work |
This patch does part of the job. In my test it successfully gets rid of extra fields on nodes that are *not yet saved*. Once the node is saved, the extra blank field returns.
#44
Nick Lewis CreditFile | Size |
---|---|
1.24 KB |
Simply adding a minus one to count($items) seems to solve it in both cases -- not sure what's going on with all this minusing of values but it does work for me.
#46
Nick Lewis CreditStatus: | Needs review | » Needs work |
Ha, nevermind this technique totally breaks table dragging. I think the code in the current patch may be on the right path, with the remainder of the fix involving the tabledrag/ahah voodoo that I haven't quite wrapped my head around.
#48
Gyt CreditOnce the node is saved, the extra blank field returns.
It isn't a big problem for me. If you want to solve it, try this patch or CCK 3.0 (dev version).
My patch only solve problem in the title: "two empty fields showing up - make it one".
#49
tmsimont CreditThis is what I did to solve the problem ->
for the function in content.node_form.inc called content_multiple_value_form(&$form, &$form_state, $field, $items)
I edited case 1 of the first switch statement,
switch ($field['multiple']) {
...
case 1:
$filled_items = content_set_empty($field, $items);
$current_item_count = isset($form_state['item_count'][$field_name])
? $form_state['item_count'][$field_name]
: count($items);
// We always want at least one empty icon for the user to fill in.
//no I don't!
$max = ($current_item_count == 0)
? $current_item_count
: $current_item_count - 1;
break;
...
Seems to work fine for me... any issue with doing this?
#50
ManyNancy CreditVersion: | 6.x-2.3 | » 6.x-2.x-dev |
Is this going into the module? Which patch is recommended?
#51
markus_petrux CreditTo get this in, it should be optional as in #12, but it needs to follow indications in #13. That means, this needs:
1) Add a new option to widget settings form (patch in #12 is a good example).
2) Adjust CRUD code to handle this new option (sadly, this is not covered by #12, it uses Drupal variables instead, which is wrong here).
3) Apply the option to multiple value widgets in node edit form.
4) Test, test, test...
#52
uomeds Credit#36 works great for me with cck 2.5. One "unlimited" location field was showing up double, and now it shows up once. My "unlimited" e-mail and phone fields are still showing up double/triple for old users, but in new users starting with all fields blank, it displays only one field as expected.
Definitely a successful patch if you apply it before your members all sign up and initially fill out their fields. Thanks.
#54
userok CreditAs a quick test option, you could also try making the first field and its handlebar invisible by using CSS.
#56
nick.dap CreditThe following form alter is what I'm using. I don't know how safe it is, but based on limited testing it seems to work for new node form, edit form, and also "Add another item" button seems to work as intented. How safe is it to do this?
/*
* Remove the extra empty field on multiple valued CCK fields
*/
function dap_theme_form_alter(&$form, &$form_state, $form_id) {
if( $form['#id'] == 'node-form' ) {
$content_type = content_types($form['#node']->type);
foreach( $content_type['fields'] as $field_name => $field ) {
if( $field['multiple'] ) {
$num_of_filled_values = count($form['#node']->$field_name);
$index_of_extra_form_field = max($num_of_filled_values, 1);
unset($form[ $field_name ][$index_of_extra_form_field]);
}
}
}
}
#59
gausarts CreditSubscribing, looking for better solution. Currently had to work around by injecting a fake button after the table with jquery, keeping one field visible and hide the rest, and toggle subsequent fields to show one after another with a big caveat that when two or more fields are filled already, they will be folded/hidden unless the button is clicked again :(
Thanks
#60
john.money Credit+1 patch #36 by Gyt (which is same as patch #5 by yang_yi_cn but without comments).
Tested
CCK 2.6
Drupal 6.16
PHP 5.29
Tested compatible with
CCK Fieldgroup Tabs 1.2
Flexifield 1.x-dev (2010-Apr-11)
Modal Frame CCK Editor 1.0
Providing widget level configuration would be just one more (unnecessary) step for every unlimited value field I would have to do since I can't think of a scenario where 2 empty fields would ever be preferred. My 0.02...
#63
jason.fisher CreditYes. Love it.. thank you. Agree that two empty is pointless and frustrating clutter.
#66
gagarine CreditStatus: | Needs work | » Reviewed & tested by the community |
I also applied the patch #36 with success.
I make some user test on 10 peoples. It's pretty obvious than the majority (100% for me) prefer one field. The default should be one. And perhaps an other module can add multiple field as an option...
#67
alexkb CreditPatch #36 works on the latest Drupal 6.19 and CCK 6.x-2.8. Thanks for fixing this annoying bug!
#68
kento Credit#70
nirmal_george CreditIssue tags: | +CCK, +multiple fields |
<?php
/*
* Remove the extra empty field on multiple valued CCK fields
*/
function dap_theme_form_alter(&$form, &$form_state, $form_id) {
if( $form['#id'] == 'node-form' ) {
$content_type = content_types($form['#node']->type);
foreach( $content_type['fields'] as $field_name => $field ) {
if( $field['multiple'] ) {
$num_of_filled_values = count($form['#node']->$field_name);
$index_of_extra_form_field = max($num_of_filled_values, 1);
unset($form[ $field_name ][$index_of_extra_form_field]);
}
}
}
}
?>
#72
eosrei Creditsubscribe. +1 to #5 and #36
#76
koppie Credit+1 for #36.
I noticed that Gyt submitted his patch June 2009. This issue was marked "Reviewed & tested by the community" on 8/10/2010. CCK's latest stable version was released 8/11/2010. It is now 12/1/2010. When is this patch going to make it into a stable version?
Thanks!
#77
jsobiecki CreditFile | Size |
---|---|
1 KB |
I attached very slighty modified version of patch from #36. I only changed path to modified file. This change is needed, becouse according to http://drupal.org/patch/create all patches should be applied from root directory of module. This makes possible to apply this patch using drush_make.
#78
SeanA CreditProper fixes for the way cck multiple values are handled are here (for 2.x): #530828: Provide "Add more values" button for fields (and multigroups) with fixed number of multiple values
and here for (3.x 'multigroup'): #841914: Provide options to set how many fields are initially displayed and how many are added on click of "add more"
#79
babbage Credit#77 worked for me with CCK 6.x-2.8 on Drupal 6.20.
I regret to say I cannot understand the logic at all for thinking that two blank fields makes sense as a default for an unlimited-values field. This has always seemed to be a huge ?? for me, and I am glad to have CCK now patched with #77. I never hack core and never hack modules if I can avoid it, but fixing this was a total non-negotiable for the client site I'm working on at present so I will just have to maintain this modification until CCK implements it. Please!
#82
imclean CreditStatus: | Reviewed & tested by the community | » Needs review |
File | Size |
---|---|
5.56 KB |
The patches in #36 and #77 will never be committed for reasons clearly stated in #8, #13 and #51.
This patch is based on #12 and adds an extra field to the content_node_field_instance table. I'm not sure of the correct way to handle this, I added it manually to the database and updated the schema in content.install. Upgrading the module and a fresh install have not been tested.
I'm also not sure if the git patch creation process is correct, the instructions on drupal.org seem to mix up module maintainers with patch submitters.
#83
imclean CreditFile | Size |
---|---|
6.23 KB |
Please ignore the above patch, this one should actually create the field.
#84
imclean CreditFile | Size |
---|---|
6.44 KB |
Updated schema version. Learn something new every minute.
Although if it's not in D7 then it may not go anywhere.http://drupal.org/node/530828#comment-3998880
#85
witti CreditPatch #84 applied correctly and generally works fine. However, I get the wrong number of text fields when creating a new node or editing a node that has no values for that field. I get one fewer on the form than selected in the field configuration. Still, it is a great patch -- very useful for data entry.
#86
eighthourlunch CreditPatch #84 worked great for me, thanks! One potential gotcha, though. If you're using source control, Mercurial locked the file and made it unreadable at first, giving me this error:
Fatal error: require_once() [function.require]: Failed opening required './modules/cck/includes/content.node_form.inc' (include_path='.;\xampp\php\PEAR') in \xampp\htdocs\includes\module.inc on line 274
Restoring correct file permissions and recommitting the files fixed it.
#94
retrodans Credit@JGonzalez did you find a solution for D7 at all? Is there a seperate thread I can subscribe to on the topic for D7 and help with a solution?
Dan
#96
anthony0perez CreditIs there a fix yet for Drupal 6? Do any of these patches work good for production?