I have a multi-value double field (text field/text field).
for styling purpose I need the correct snippet of code that gets the character's count of the field which has the max length among the rest.
and depending on this value i can choose which css class is suitable for the whole multiple fields.
I mean I want to build my style upon the maximum length, so it will not break.
like if max length < 30 Chars , then select (short text class) <== taxonomy term
like if max length between 31-50 Chars , then select (medium text class)
like if max length > 50 Chars , then select (long text class)
With little php knowledge. but can I improve it. and with using this combination of two modules which can save a lot of time and effort :
1- Field Formatter CSS Class can change the css class for this field ( by selecting a taxonomy term which represent a css class)
2- CSS field formatters which can accept php snippets and can programmatically modify the CSS class term field (mention above #1)
- snippets are preferred , but other solutions are very welcome.
Comments
Comment #2
Chi CreditAttribution: Chi commentedThat's fairly simple. You can override theme function and calculate field length there.
Comment #3
theroyal CreditAttribution: theroyal commentedis this snippet ready to use in
1- CSS Field formatters module ?
OR
2- I need to add it to the theme files ?
Comment #4
Chi CreditAttribution: Chi commentedIt should be placed to template.php file of your theme.
Comment #5
theroyal CreditAttribution: theroyal commentedI really appreciate your help, and what i did is :
1- removed the (php) ? at the start and end.
2- replaced YOURTHEME with the theme name.
3- I added the code at the end of template
i have few questions:
1- Am I correct in the above steps? sorry its almost my 1st time to deal with code in drupal.
2- do I have to modify any other values in the code?
3- do I have to add a certain class in my style.css file? I mean did you add one or more in the code as an example?
4- I understand that this code will let me to avoid using the modules I mentioned in the issue. am I right?
5- does it count each subfield (this what is needed),
or the sum of sub1st+sub2nd (this is not what i mean)?
Comment #6
Chi CreditAttribution: Chi commentedThe function should be placed to your template.php file. It counts values of each subfield and provides CSS classes (text-long, text-short).
Comment #7
theroyal CreditAttribution: theroyal commentedok got it.
am so sorry for bothering
1- I want if the value is (long) I need to apply 2 classes not one:
a- subfield1-long-text (for all subfield1) so i can allign left for example.
b- subfield2-long-text (for all subfield2) so i can allign right for example.
2- what about if I want to have more selections like :
0-25 very-short
26-40 short
41-55 miduim
56-70 long
70 < very long
Comment #8
theroyal CreditAttribution: theroyal commentedafter re-look to the code, i noticed the following :
1- you are trating the subfield1 seperately than subfield2.
the needed is : check in both subfield1 and subfield2, find the any field which has the highest value in length.
lets say :
subfield1 | subfield2
20 | 15
31 | 34
11 | 99
so the value is (99)
then the we will set:
for subfield1: subfield1-very-long-class
for subfield2: subfield2-very-long-class
thats it
2- you are providing only 2 options long and short, while i need more options as mentioned in the earlier comment.
Comment #9
Chi CreditAttribution: Chi commentedIt's just an example of how it could be done. The code is very simple. You can modify it as you wish even you have never worked with PHP.
Comment #10
theroyal CreditAttribution: theroyal commentedyes the code looks great and simple
and I really appreciate your help.
but am afraid that the most important issue -which is doublefield related- is not clear yet,
maybe i didnt explain it very well.
I want to check all values and for both subfields,
example:
if i have 10 multivalues and each value has 2 subfields, then we have 20 subfields values here.
so the wanted is the highest length among these 20 subfields.
thats it.
maybe we need a loop here ?
if it needs a loop, then how to implement it with doublefield.
Comment #11
Chi CreditAttribution: Chi commentedLoop does not help in this function because it takes only on field value. You have to implement custom field formatter which is much more complected or use javascript.
Comment #12
theroyal CreditAttribution: theroyal commentedok what about if I need it to set the css class only when this field is filled or updated.
what is the recommended way ?
Comment #13
Chi CreditAttribution: Chi commentedI don't even know. Some custom module perhaps.
Comment #14
theroyal CreditAttribution: theroyal commentedok thanks for your valuable tips.
really it was a great help.
Comment #15
Chi CreditAttribution: Chi commented