I am new to Vue.js and I am currently trying to figure out how to maintain whitespaces in the options of my HTML "select" drop-down. I am using v-for to populate the list like this:
<option
v-for="category in displayCategories"
:key="category">
{{ category }}
</option>
And the list items look like this (in a string array):
`SECTOR`,
` Food and Drink`,
` Education`,
` Transport`
Currently, something seems to be trimming out the space characters. I'm not sure if the problem lies with Vue or HTML...
Thanks for your time,
Josh
Related
I am rendering a list using *ngFor. I only want the next item to be rendered using index. I have tried a number of things but can't get it to work:
Next: {{ exhibit{{ i + 1 }}.fields.artist }}
Next: {{ exhibit[i + 1].fields.artist }}
What am I doing wrong?
Not sure why you do you want to render a list like this, but you can accomplish this using ngFor as below. You need to write the entire template expression inside double curly braces instead of just index.
Next: {{ exhibit[i + 1].fields.artist }}
Please find proof of concept here: https://stackblitz.com/edit/angular-cwxgee
<img [src]=post.$value.split("|")[2]>
I want to bind the value post.$value.split("|")[2] to an image source. It is simply a string that comes from another string I have split. I want to avoid looping through another array since I have
*ngFor = 'let post of posts | async'
As the ngFor statement that loops over my elements and that is a FirebaseListObservable which I would like to avoid to mess with and keep like it is. For some reason html doesn't recognize the square brackets in the expression. What do I do, Angular won't recognize it using either the input [] syntax or the {{}}syntax.
You should surround your expression with quotes :
<img [src]="post.$value.split('|')[2]">
I am using Live Templates in PHPStorm to easily create blocks of code using variables I define. I created a live template block that creates a group of elements for a text form field using the blade templating engine.
<!--- $VALUE$ Field --->
<div class="form-group">
{{ Form::label('$NAME$', '$VALUE$') }}
{{ Form::text('$NAME$', null, []) }}
</div>
I set up the variables so that I can enter the NAME variable first in all lowercase letters, and it will then automatically fill in the VALUE variable for me while capitalizing the first letter.
Here's an example of how that works out when the name variable is a single word:
<!--- Address Field --->
<div class="form-group">
{{ Form::label('address', 'Address') }}
{{ Form::text('address', null, []) }}
</div>
This works great, but I run into a problem when the field name has two words. I prefer to use underscores between two words for the NAME attribute, and unfortunately that underscore appears in the VALUE variable as well.
<!--- Zip_code Field --->
<div class="form-group">
{{ Form::label('zip_code', 'Zip_code') }}
{{ Form::text('zip_code', null, []) }}
</div>
I can't find a expression in the live template variables setup that allows me to replace an underscore with a space. Ideally I would like to keep the first letter capitalized while also replacing any underscores with spaces for the VALUE variable. Any ideas how I can achieve this?
underscoresToSpaces(String) should do the thing. Like:
capitalize(underscoresToSpaces(NAME))
I want to make something like this:
<select>
<option>Column1abc Column2klmn Column3</option>
<option>Column1defgh Column2opr Column3</option>
<option>Column1ij Column2stuvwxyz Column3</option>
</select>
with <style>select option { font-family: courier;} </style>
But the rendered result is without multiple spaces.
If I use instead of "", I get as string, not as non-breaking space.
How can I fix that?
The problem here is that Twig will automatically escape HTML entities (calling htmlspecialchars, effectively). Since you want to send a literal string of HTML, you don't want the automatic escaping to be done.
Now, you haven't provided your Twig code, so I can't say exactly how you should do this. But my guess is that you're including it with something like this:
{{ table.column }}
You need to use the raw filter:
{{ table.column | raw }}
You do need to be careful here, though. If the values in the column can come from a user, you're opening yourself up to an XSS attack.
works !!!!
<select>
<option>Column1abc Column2klmn Column3</option>
<option>Column1defgh Column2opr Column3</option>
<option>Column1ij Column2stuvwxyz Column3</option>
</select>
//use code
select{word-spacing:1px;}
I'm trying to fill select element with . List has three items with one of them is json data. When gsp page is rendreded this is what is in html:
<option a":"aa11","b":"bb33","cc":"cc44"}"="" value="{">label </option>
Is this a bug in Grails 2.0.4 ?
You should escape HTML characters in optionKey
Example :
<g:select optionKey="id" optionKey="${{it.toString().encodeAsHTML()}}" name="book.title" from="${bookList}" />