I have this piece of LESS code:
.generate-spans(#columns; #prefix; #current: 1) when (#current =< #columns) {
.span-#{prefix}-#{current} {
width: (#current/#columns*100%);
}
.generate-spans(#columns, #prefix, (#current + 1));
}
.generate-spans(12, "large");
It is suppose to generate something like this:
.span-large-1 {
width: 8.333333333333332%%;
}
.span-large-2
width: 16.666666666666664%;
}
.....
But it just returns error: Operation on an invalid type in ....
How do i make the code work as intended?
Your code works in Less 1.7.0. Try it here: http://lesstester.com/
The only typo is the name in quotes, which you should remove:
.generate-spans(12, large);
And that fix might also make it work in the version of Less that you are using.
If for some reason you have to use quotes, you can also try:
.generate-spans(12, ~"large");
Which will remove the quotes from the resulting CSS.
Related
here i want to create a less mixin. The parameter is brand and is should be changed into brand#2x.png. The code below did not work.
.bglogo (#brand) {
#brandurl: #brand + '#2x.png';
background-image: url(#brandurl);
}
.span{
.bglogo('brand');
}
error message --
You need to use variable interpolation in order to concatenate the variable and the string.
In your case, you would use the value "#{brand}#2x.png":
.bglogo (#brand) {
#brandurl: "#{brand}#2x.png";
background-image: url(#brandurl);
}
.span {
.bglogo('brand');
}
Result:
.span {
background-image: url("brand#2x.png");
}
I have a LESS mixin with this code:
.generated_width (#margins:40px)
{
-webkit-width:calc(~"100% - " #margins );
-moz-width:calc(~"100% - " #margins );
width:calc(~"100% - " #margins );
}
But sometimes I need to OPTIONALLY specify a % width different, for example "50%". Obviously, I could create another specific, but different, mixin with "50%" replacing "100%", but I prefer to pass this value as a parameter.
Is there a way to edit my mixin in order to OPTIONALLY accept a parameter that overrides default value of "100%" ? In other words, sometime the call could be:
.generated_width (40px)
Others
.generated_width (50%,40px)
So you have
.generated_width (#margins: 40px, #per: 100%)
{
-webkit-width:calc(~"#{per} - " #margins );
-moz-width:calc(~"#{per} - " #margins );
width:calc(~"#{per} - " #margins );
}
When called
.generated_width (40px)
.generated_width (40px, 40%)
I think depending on your LESS version you can also do
.generated_width (#per:40%)
This way you can specify as many optional parameters as you want. This is much more flexible but a little bit more code to type. So if you only have 1 optional param then just leave it at the last spot
The code below is action taken when a button is clicked on a simple form. The problem comes with the one if/else block. The If line is not terminated. The Else line is not terminated. But I have a consistent error that my Else exists without an If. I can't see why. I need someone smarter than me to identify what is going on here.
Thank you in advance!
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
FileFilter filter;
filter = new FileNameExtensionFilter("Comma Separated Value files","csv","txt");
JFileChooser chooser;
chooser = new JFileChooser();
chooser.addChoosableFileFilter(filter);
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int showDialog = chooser.showDialog(this, null);
File selectedFile = chooser.getSelectedFile();
String filename;
filename = selectedFile.getAbsolutePath();
if (filter.accept(selectedFile))
{
jTextField2.setText(filename);
jTextField2.setBackground(Color.white);
else
jTextField2.setText("You Did NOT Select a CSV File.");
jTextField2.setForeground(Color.black);
jTextField2.setBackground(Color.red);
}
}
You are missing the bracket '}' after "jTextField2.setBackground(Color.white);" and else.code is here
if (filter.accept(selectedFile))
{
jTextField2.setText(filename);
jTextField2.setBackground(Color.white);
}
else
{
jTextField2.setText("You Did NOT Select a CSV File.");
jTextField2.setForeground(Color.black);
jTextField2.setBackground(Color.red);
}
The SYNTAX for if-else Block looks like this:-
if {
// statements
} else {
//statements
}
Now if you are having only ONE statement inside the if Or else part then you can afford to skip the curly braces{ } otherwise you surely need to put those curly braces as compiler looks for it can terminate the execution of if statement.
However, it is always recommended to use the braces even if u have only ONE statement inside the if or else part as it improves the readability of the code.
You need to close your "if" and "else" blocks.
Example: if {} else {}.
if (filter.accept(selectedFile)) {
jTextField2.setText(filename);
jTextField2.setBackground(Color.white);
} else {
jTextField2.setText("You Did NOT Select a CSV File.");
jTextField2.setForeground(Color.black);
jTextField2.setBackground(Color.red);
}
The if's closing bracket is missing just before the else.
Currently extjs numberfield is allowing '-' hyphen otherthan numbers into the field. how to restrict that from typing? if i give custom vtype validation it is checking only after i submit that.
use autoStripChars and remove hyphen from allowed in initComponent. corrected code below.
autoStripChars: true,
initComponent: function() {
var me = this,
allowed;
me.callParent();
me.setMinValue(me.minValue);
me.setMaxValue(me.maxValue);
// Build regexes for masking and stripping based on the configured options
if (me.disableKeyFilter !== true) {
allowed = me.baseChars + '';
if (me.allowDecimals) {
allowed += me.decimalSeparator;
}
/* removed code
if (me.minValue < 0) {
allowed += '-';
}
*/
allowed = Ext.String.escapeRegex(allowed);
me.maskRe = new RegExp('[' + allowed + ']');
if (me.autoStripChars) {
me.stripCharsRe = new RegExp('[^' + allowed + ']', 'gi');
}
}
}
You need to create custom VType. VType validation is called after any change in the textfield and you have ability to configure what characters are allowed to be entered:
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.VTypes
Take a look at xxxMask property.
You could also use a regular Textfield with a maskRe config.
maskRe: /[0-9]/
Similar to #lagnat's reply which is a whitelist you can blacklist characters using stripCharsRe config.
stripCharsRe: /-/
If you are wanting to restrict negative values.
minValue: 0
{
minValue: 0,
autoStripChars: true,
allowExponential: false
}
I've noticed that when ordering by a datetime column in CI with active record, it's treating the column as a string, or int.
Example:
$this->db->limit(12);
$this->db->where('subscribed',1);
$this->db->join('profiles','profiles.user_id=users.id');
$this->db->where('active',1);
$this->db->select('users.thumbUpload,users.vanity_url');
$this->db->select('users.created_on as time');
$this->db->order_by('time');
$query = $this->db->get('users');
This is where users.created_on is a datetime field. Firstly, is it because active record is rendering time escaped, or is it something else? And if it is, can I prevent the escaping on order_by somehow?
Also, stackoverflow, please stop autocorrecting 'datetime' to 'date time'. It's annoying.
Cheers!
When you set second argument as false, function wont check and escape string. Try this
$this->db->select('users.created_on as time', FALSE);
Or for you query use
$this->db->order_by('users.created_on', 'DESC'); //or ASC
And for complex queries
$this->db->query("query");
According to the signature of the method in core files of CI (currently 2.2), it does not have any option to allow to choose whether or not to escape.
// The original prototype of the order_by()
public function order_by($orderby, $direction = '') {
// Definition
}
As you see there is not argument as $escape = true in the argument list. One way to do so is to hack this core file (I normally do not suggest it, since if you upgrade CI to a newer version later, then these changes will be lost, but if you do not intend to do so, it is OK to use it).
To do so, first change the prototype as:
public function order_by($orderby, $direction = '', $escape = true) {
// Definition
}
And then check the conditions in the following parts of definition:
// Line 842
if($escape){
$part = $this->_protect_identifiers(trim($part));
}else {
$part = trim($part);
}
// Line 856
if($escape){
$orderby = $this->_protect_identifiers($orderby);
}
When you call it, to prevent the escaping:
$this->db->order_by($ORDERBY_CLAUSE, null, false);