Right-alignment for numeric fields
#1
Posted 04 November 2009 - 06:33 PM
I'm a complete Yii newbie (started using it yesterday). I created some forms using crud command and now I want all the numeric fields to have content aligned to the right. This is done via CSS text-alignment: right but I cannot find how do to this with CHtml::activeTextField.
I even tried to google for about half an hour, learned a lot of other stuff about Yii, but not this.
Thanks,
M.
#2
Posted 04 November 2009 - 06:44 PM
echo CHtml::activeTextField($model,'price', array('style'=>'text-align: right'));
However, it is very cumbersome to have to do this for every numeric field. Since Yii already knows which fields are numerical (specified in rules), it would be nice to have them all aligned to right.
I hope this has already been done, but I'm failing to discover it?
#3
Posted 04 November 2009 - 08:49 PM
Milan Babuskov, on 04 November 2009 - 06:44 PM, said:
echo CHtml::activeTextField($model,'cena', array('style'=>'text-align: right'));
However, it is very cumbersome to have to do this for every numeric field. Since Yii already knows which fields are numerical (specified in rules), it would be nice to have them all aligned to right.
I hope this has already been done, but I'm failing to discover it?
apply a class to numberic fields eg: class=>"numeric" and specify a css rule like .numeric {test-align:right;}
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";
python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]
ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}
You say Tomato, I say Tomato.
#4
Posted 04 November 2009 - 09:25 PM
jayrulez, on 04 November 2009 - 08:49 PM, said:
This is exactly what I'm trying to avoid. Since Yii already knows which fields are numeric, it would be nice if it would set this class automatically. Or, at least, if "crud" command of yiic shell would add the class to generated view code. Of course, I would then specify CSS style for that class.
Can I submit a feature request somewhere? I believe this would be a useful feature for all Yii users.
Thanks,
M.
#5
Posted 04 November 2009 - 10:24 PM
Milan Babuskov, on 04 November 2009 - 09:25 PM, said:
Can I submit a feature request somewhere? I believe this would be a useful feature for all Yii users.
Thanks,
M.
That's a bit application or individual specific isn't it?
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";
python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]
ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}
You say Tomato, I say Tomato.
#6
Posted 05 November 2009 - 01:24 AM
jayrulez, on 04 November 2009 - 10:24 PM, said:
I don't think so. Don't you have numeric fileds in your databases? How do you align them in visual representation?
It is very common for numbers to be right-aligned. Take a look at Excel or OpenOffice and how they format numbers by default. Even this forum right-aligns the number of posts in each thread. Any tabular representation also has numbers right-aligned. PHP function sprintf also defaults to right-align when you specify numeric format like '%8d' for example - it pads to 8 characters with spaces prepended.
BTW, same applies to "admin" view that is generated by "crud" command. All numerical columns should be right-aligned by default.
#7
Posted 05 November 2009 - 07:03 AM
The only way to align at right in html is throught some atribute (css or style or the 'old way' align="right")
Now, because it's true that yii knows what fields are numeric, you can extend the command crud and take kare of them adding a class o whatever you want. (so when you use the extended crud, this class will be applied to al numeric fields and will respond to your css)
Yii can do magic... but you are the responsible to teach the magic!
How to extend yiic shell commands
The problem is communication! Excess of communication!
#8
Posted 09 November 2009 - 12:43 PM
#9
Posted 09 November 2009 - 02:15 PM
xx666xx's method might be easier, but it has a performance hit

Help














