Comments (5)
Ohh yeah, I believe it is not documented well, but for nested values, you make use of $parent
keyword.
So it should be
$parent.field.name
from edge.
@thetutlage thanks for reply
I've tried your example, and it works well. Here is my full template that produce given error. I guess this issue occurred when using nested loops.
Template:
@layout('dashboard/layout')
@section('content')
<form class="forms" method="post">
@each(field in fields)
<div class="content-block">
<div class="field {{ field.type }} {{ field.required ? "required" : "" }}">
<h2 class="title"> {{ field.title }}</h2>
<div class="description">{{ field.description }}</div>
{{-- Text fields --}}
@if(field.type == 'text')
<input type="text" name="{{ field.name }}" {{ field.required ? "required" : "" }} value="{{ field.value ? field.value : "" }}" >
@endif
{{-- Number fields --}}
@if(field.type == 'number')
<input type="number" id="{{ field.name }}" name="{{ field.name }}" min="{{ field.min }}" max="{{ field.max }}" step="{{ field.step }}" value="{{ field.value ? field.value : "" }}" {{ field.required ? "required" : "" }} />
@endif
{{-- Textarea fields --}}
@if(field.type == 'textarea')
<textarea name="{{ field.name }}" cols="{{ field.cols }}" rows="{{ field.rows }}" {{ field.required ? "required" : "" }}>{{ field.value ? field.value : "" }}</textarea>
@endif
{{-- Radio buttons fields --}}
@if(field.type == 'radio')
<fieldset id="{{ field.name }}">
@each(radioItem in field.data)
<span class="radio-item">
<input type="radio" id="{{ radioItem.name }}" name="{{ field.name }}" value="{{ radioItem.value }}" {{ field.checked ? "checked" : "" }} {{ field.required ? "required" : "" }}>
<label for="{{ radioItem.name }}">{{ radioItem.title }}</label>
</span>
@endeach
</fieldset>
@endif
{{-- Checkbox fields --}}
@if(field.type == 'checkbox')
<fieldset id="{{ field.name }}">
@each(checkBoxItem in field.data)
<span class="checkbox-item">
<input type="checkbox" id="{{ checkBoxItem.name }}" name="{{ field.name }}" value="{{ checkBoxItem.value }}" {{ checkBoxItem.checked ? "checked" : "" }}>
<label for="{{ checkBoxItem.name }}">{{ checkBoxItem.title }}</label>
</span>
@endeach
</fieldset>
@endif
{{-- Select fields --}}
@if(field.type == 'select')
<select name="{{ field.name }}" id="{{ field.name }}" {{ field.required ? "required" : "" }} {{ field.multiple ? "multiple" : 0 }}>
@each(selectItem in field.data)
<option value="{{ selectItem.value }}" {{ field.selected ? "selected" : "" }}>{{ selectItem.title }}</option>
@endeach
</select>
@endif
{{-- Range fields --}}
@if(field.type == 'range')
<input type="range" id="{{ field.name }}" name="{{ field.name }}" min="{{ field.min }}" max="{{ field.max }}" step="{{ field.step }}" value="{{ field.value }}" oninput="{{ field.name }}_output.value = {{ field.name }}.value" />
<output name="{{ field.name }}_output" id="{{ field.name }}_output">{{ field.value }}</output>
@endif
</div>
</div>
@endeach
{{ csrfField() }}
<input type="submit" value="Отправить">
</form>
@endsection
Controller:
return view.render('dashboard/fields', {
fields:
[
{
type: "radio",
name: "gadget_type",
title: "Тип устройства",
description: "Выбериты тип устройства",
required: true,
data: [
{ name: "smartphone", title: "Смартфон", value: "smartphone" },
{ name: "phablet", title: "Фаблет", value: "phablet" },
{ name: "phone", title: "Телефон", value: "phone" },
]
},
]
})
output:
<fieldset id="gadget_type">
<span class="radio-item">
<input type="radio" id="smartphone" name="undefined" value="smartphone" >
<label for="smartphone">Смартфон</label>
</span>
<span class="radio-item">
<input type="radio" id="phablet" name="undefined" value="phablet" >
<label for="phablet">Фаблет</label>
</span>
<span class="radio-item">
<input type="radio" id="phone" name="undefined" value="phone" >
<label for="phone">Телефон</label>
</span>
</fieldset>
from edge.
Seems to be working fine for me with this route and view
Route.on('/').render('welcome', {
field: {
type: 'checkbox',
name: 'foo',
data: [
{
name: 'age',
value: 22,
title: 'Age'
}
]
}
})
@if(field.type == 'checkbox')
<fieldset id="{{ field.name }}">
@each(checkBoxItem in field.data)
@debugger
<span class="checkbox-item">
<input type="checkbox" id="{{ checkBoxItem.name }}" name="{{ field.name }}" value="{{ checkBoxItem.value }}" {{ checkBoxItem.checked ? "checked" : "" }}>
<label for="{{ checkBoxItem.name }}">{{ checkBoxItem.title }}</label>
</span>
@endeach
</fieldset>
@endif
from edge.
@PazzaVlad Same issue here.
from edge.
Closing since no response from the issue reporter and not actionable as well
from edge.
Related Issues (20)
- Links are dead in legacy documentation HOT 1
- Simplify prop binding and conditional props HOT 2
- Issue while rendering string having spaces HOT 3
- Condition in one line HOT 2
- Is there a better way to import multiple functions? HOT 4
- Unable to display an image HOT 1
- Is it possible to perform a static analysis of the template Edge.js ? HOT 4
- Just a silly question HOT 2
- Passing values from edge to alpine.js (Question) HOT 3
- Merging props with a default value HOT 1
- SEO HOT 1
- Can not use @ symbol in template files HOT 2
- Blaze/Handlebars vs Edge HOT 1
- <named slot> is not a function HOT 6
- SVG icons not working HOT 5
- Question: What is the difference between partial and component? HOT 2
- `sentenceCase` helper remove accented chars HOT 1
- Creating new feature request does not seem to be possible HOT 2
- Discussion for a new feature - Globally disable html escaping HOT 1
- Discussion for a new feature - @continue and @break tag HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from edge.