Bind record data to input form values in sails.js
I am pretty new to Sails.js. I am trying to grab the records from the database in the controller. Then in my ejs file I have the below code to create an ajax-form for each record in the database (gives them the ability to update the records. I am not sure what I am doing wrong.
fn: async function (inputs, exits) {
var maplayers = await Maplayers.find().populate('layerstyle');
return exits.success({
maplayers: maplayers
});
}
Then in my ejs file I have:
<% _.each(maplayers, function (maplayer) { %>
<ajax-form action="updateMaplayers" :syncing.sync="syncing" :cloud-error.sync="cloudError" @submitted="updateMapLayerSubmit()" :handle-parsing="handleUpdateMaplayerParsingForm">
<div class="accordion" id="maplayers-accordion">
<div class="card">
<div class="card-header" id="maplayer-header" data-toggle="collapse" data-target="#collapseOne-<%= maplayer.layerid %>">
<h5 class="mb-0">
<button class="btn btn-link maplayer-header-btn" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<%= maplayer.name %>
</button>
</h5>
</div>
<div id="collapseOne-<%= maplayer.layerid %>" class="collapse" aria-labelledby="headingOne" data-parent="#maplayers-accordion">
<div class="card-body">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="maplayer-editlayerid">Layer ID</label>
<input class="form-control" id="maplayer-editlayerid" name="maplayer-editlayerid" type="text" value="<%= maplayer.layerid %>" :class="[formErrors.editlayerid ? 'is-invalid' : '']" v-model.trim="formData.editlayerid" focus-first>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="maplayer-editlayertype">Layer Type</label>
<select class="form-control" id="maplayer-editlayertype">
<option value="point" <%= maplayer.layertype == 'point' ? 'selected' : ''%> >Point</option>
<option value="polygon" <%= maplayer.layertype == 'polygon' ? 'selected' : ''%> >Polygon</option>
<option value="line" <%= maplayer.layertype == 'line' ? 'selected' : ''%> >Line</option>
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="maplayer-editname">Layer Name</label>
<input class="form-control" id="maplayer-editname" name="maplayer-editname" type="text" value="<%= maplayer.name %>">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="maplayer-edittable">Table</label>
<input class="form-control" id="maplayer-edittable" name="maplayer-edittable" type="text" value="<%= maplayer.layertableref %>">
</div>
</div>
<div class="col-sm-4">
<label for="maplayer-editmin">Minimum Zoom</label>
<input class="form-control" id="maplayer-editmin" name="maplayer-editmin" type="number" value="<%= maplayer.minzoom %>">
</div>
<div class="col-sm-4">
<label for="maplayer-editmax">Maximum Zoom</label>
<input class="form-control" id="maplayer-editmax" name="maplayer-editmax" type="number" value="<%= maplayer.maxzoom %>">
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="maplayer-editatt">Attributes to Display:</label>
<textarea class="form-control" rows="3" id="maplayer-editatt" name="maplayer-editatt" ><%= maplayer.layerattributesonclick %></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="maplayer-editurl">URL:</label>
<textarea class="form-control" rows="3" id="maplayer-editurl" name="maplayer-editurl" ><%= maplayer.url %></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<p class="text-danger" v-if="cloudError === 'emailAlreadyInUse'">There is already an account using that email address.</p>
<p class="text-danger" v-else-if="cloudError">An error occured while processing your request. Please check your information and try again, or <a href="/contact">contact support</a> if the error persists.</p>
</div>
<div class="col-sm-6">
<div class="form-group text-right">
<button type="button" class="btn btn-warning fontColor" @click="hideAddForm()">Cancel</button>
<ajax-button type="submit" :syncing="syncing" class="btn btn-success">Save changes</ajax-button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</ajax-form>
<% }) %>
I do not know why the input in the maplayers-editlayerid is blank? This is the Layer ID Field. Why is the value=<% maplayer.editlayerid %> not being set?
sails.js
add a comment |
I am pretty new to Sails.js. I am trying to grab the records from the database in the controller. Then in my ejs file I have the below code to create an ajax-form for each record in the database (gives them the ability to update the records. I am not sure what I am doing wrong.
fn: async function (inputs, exits) {
var maplayers = await Maplayers.find().populate('layerstyle');
return exits.success({
maplayers: maplayers
});
}
Then in my ejs file I have:
<% _.each(maplayers, function (maplayer) { %>
<ajax-form action="updateMaplayers" :syncing.sync="syncing" :cloud-error.sync="cloudError" @submitted="updateMapLayerSubmit()" :handle-parsing="handleUpdateMaplayerParsingForm">
<div class="accordion" id="maplayers-accordion">
<div class="card">
<div class="card-header" id="maplayer-header" data-toggle="collapse" data-target="#collapseOne-<%= maplayer.layerid %>">
<h5 class="mb-0">
<button class="btn btn-link maplayer-header-btn" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<%= maplayer.name %>
</button>
</h5>
</div>
<div id="collapseOne-<%= maplayer.layerid %>" class="collapse" aria-labelledby="headingOne" data-parent="#maplayers-accordion">
<div class="card-body">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="maplayer-editlayerid">Layer ID</label>
<input class="form-control" id="maplayer-editlayerid" name="maplayer-editlayerid" type="text" value="<%= maplayer.layerid %>" :class="[formErrors.editlayerid ? 'is-invalid' : '']" v-model.trim="formData.editlayerid" focus-first>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="maplayer-editlayertype">Layer Type</label>
<select class="form-control" id="maplayer-editlayertype">
<option value="point" <%= maplayer.layertype == 'point' ? 'selected' : ''%> >Point</option>
<option value="polygon" <%= maplayer.layertype == 'polygon' ? 'selected' : ''%> >Polygon</option>
<option value="line" <%= maplayer.layertype == 'line' ? 'selected' : ''%> >Line</option>
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="maplayer-editname">Layer Name</label>
<input class="form-control" id="maplayer-editname" name="maplayer-editname" type="text" value="<%= maplayer.name %>">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="maplayer-edittable">Table</label>
<input class="form-control" id="maplayer-edittable" name="maplayer-edittable" type="text" value="<%= maplayer.layertableref %>">
</div>
</div>
<div class="col-sm-4">
<label for="maplayer-editmin">Minimum Zoom</label>
<input class="form-control" id="maplayer-editmin" name="maplayer-editmin" type="number" value="<%= maplayer.minzoom %>">
</div>
<div class="col-sm-4">
<label for="maplayer-editmax">Maximum Zoom</label>
<input class="form-control" id="maplayer-editmax" name="maplayer-editmax" type="number" value="<%= maplayer.maxzoom %>">
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="maplayer-editatt">Attributes to Display:</label>
<textarea class="form-control" rows="3" id="maplayer-editatt" name="maplayer-editatt" ><%= maplayer.layerattributesonclick %></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="maplayer-editurl">URL:</label>
<textarea class="form-control" rows="3" id="maplayer-editurl" name="maplayer-editurl" ><%= maplayer.url %></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<p class="text-danger" v-if="cloudError === 'emailAlreadyInUse'">There is already an account using that email address.</p>
<p class="text-danger" v-else-if="cloudError">An error occured while processing your request. Please check your information and try again, or <a href="/contact">contact support</a> if the error persists.</p>
</div>
<div class="col-sm-6">
<div class="form-group text-right">
<button type="button" class="btn btn-warning fontColor" @click="hideAddForm()">Cancel</button>
<ajax-button type="submit" :syncing="syncing" class="btn btn-success">Save changes</ajax-button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</ajax-form>
<% }) %>
I do not know why the input in the maplayers-editlayerid is blank? This is the Layer ID Field. Why is the value=<% maplayer.editlayerid %> not being set?
sails.js
hmmm I am reading your code and not seeing any typos on your ejs. Maybe your modal? Also just as a note its ALOT easier to read if you camelCase your attributes.editLayerId
– Raqem
Nov 20 '18 at 20:05
add a comment |
I am pretty new to Sails.js. I am trying to grab the records from the database in the controller. Then in my ejs file I have the below code to create an ajax-form for each record in the database (gives them the ability to update the records. I am not sure what I am doing wrong.
fn: async function (inputs, exits) {
var maplayers = await Maplayers.find().populate('layerstyle');
return exits.success({
maplayers: maplayers
});
}
Then in my ejs file I have:
<% _.each(maplayers, function (maplayer) { %>
<ajax-form action="updateMaplayers" :syncing.sync="syncing" :cloud-error.sync="cloudError" @submitted="updateMapLayerSubmit()" :handle-parsing="handleUpdateMaplayerParsingForm">
<div class="accordion" id="maplayers-accordion">
<div class="card">
<div class="card-header" id="maplayer-header" data-toggle="collapse" data-target="#collapseOne-<%= maplayer.layerid %>">
<h5 class="mb-0">
<button class="btn btn-link maplayer-header-btn" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<%= maplayer.name %>
</button>
</h5>
</div>
<div id="collapseOne-<%= maplayer.layerid %>" class="collapse" aria-labelledby="headingOne" data-parent="#maplayers-accordion">
<div class="card-body">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="maplayer-editlayerid">Layer ID</label>
<input class="form-control" id="maplayer-editlayerid" name="maplayer-editlayerid" type="text" value="<%= maplayer.layerid %>" :class="[formErrors.editlayerid ? 'is-invalid' : '']" v-model.trim="formData.editlayerid" focus-first>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="maplayer-editlayertype">Layer Type</label>
<select class="form-control" id="maplayer-editlayertype">
<option value="point" <%= maplayer.layertype == 'point' ? 'selected' : ''%> >Point</option>
<option value="polygon" <%= maplayer.layertype == 'polygon' ? 'selected' : ''%> >Polygon</option>
<option value="line" <%= maplayer.layertype == 'line' ? 'selected' : ''%> >Line</option>
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="maplayer-editname">Layer Name</label>
<input class="form-control" id="maplayer-editname" name="maplayer-editname" type="text" value="<%= maplayer.name %>">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="maplayer-edittable">Table</label>
<input class="form-control" id="maplayer-edittable" name="maplayer-edittable" type="text" value="<%= maplayer.layertableref %>">
</div>
</div>
<div class="col-sm-4">
<label for="maplayer-editmin">Minimum Zoom</label>
<input class="form-control" id="maplayer-editmin" name="maplayer-editmin" type="number" value="<%= maplayer.minzoom %>">
</div>
<div class="col-sm-4">
<label for="maplayer-editmax">Maximum Zoom</label>
<input class="form-control" id="maplayer-editmax" name="maplayer-editmax" type="number" value="<%= maplayer.maxzoom %>">
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="maplayer-editatt">Attributes to Display:</label>
<textarea class="form-control" rows="3" id="maplayer-editatt" name="maplayer-editatt" ><%= maplayer.layerattributesonclick %></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="maplayer-editurl">URL:</label>
<textarea class="form-control" rows="3" id="maplayer-editurl" name="maplayer-editurl" ><%= maplayer.url %></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<p class="text-danger" v-if="cloudError === 'emailAlreadyInUse'">There is already an account using that email address.</p>
<p class="text-danger" v-else-if="cloudError">An error occured while processing your request. Please check your information and try again, or <a href="/contact">contact support</a> if the error persists.</p>
</div>
<div class="col-sm-6">
<div class="form-group text-right">
<button type="button" class="btn btn-warning fontColor" @click="hideAddForm()">Cancel</button>
<ajax-button type="submit" :syncing="syncing" class="btn btn-success">Save changes</ajax-button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</ajax-form>
<% }) %>
I do not know why the input in the maplayers-editlayerid is blank? This is the Layer ID Field. Why is the value=<% maplayer.editlayerid %> not being set?
sails.js
I am pretty new to Sails.js. I am trying to grab the records from the database in the controller. Then in my ejs file I have the below code to create an ajax-form for each record in the database (gives them the ability to update the records. I am not sure what I am doing wrong.
fn: async function (inputs, exits) {
var maplayers = await Maplayers.find().populate('layerstyle');
return exits.success({
maplayers: maplayers
});
}
Then in my ejs file I have:
<% _.each(maplayers, function (maplayer) { %>
<ajax-form action="updateMaplayers" :syncing.sync="syncing" :cloud-error.sync="cloudError" @submitted="updateMapLayerSubmit()" :handle-parsing="handleUpdateMaplayerParsingForm">
<div class="accordion" id="maplayers-accordion">
<div class="card">
<div class="card-header" id="maplayer-header" data-toggle="collapse" data-target="#collapseOne-<%= maplayer.layerid %>">
<h5 class="mb-0">
<button class="btn btn-link maplayer-header-btn" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<%= maplayer.name %>
</button>
</h5>
</div>
<div id="collapseOne-<%= maplayer.layerid %>" class="collapse" aria-labelledby="headingOne" data-parent="#maplayers-accordion">
<div class="card-body">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="maplayer-editlayerid">Layer ID</label>
<input class="form-control" id="maplayer-editlayerid" name="maplayer-editlayerid" type="text" value="<%= maplayer.layerid %>" :class="[formErrors.editlayerid ? 'is-invalid' : '']" v-model.trim="formData.editlayerid" focus-first>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="maplayer-editlayertype">Layer Type</label>
<select class="form-control" id="maplayer-editlayertype">
<option value="point" <%= maplayer.layertype == 'point' ? 'selected' : ''%> >Point</option>
<option value="polygon" <%= maplayer.layertype == 'polygon' ? 'selected' : ''%> >Polygon</option>
<option value="line" <%= maplayer.layertype == 'line' ? 'selected' : ''%> >Line</option>
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="maplayer-editname">Layer Name</label>
<input class="form-control" id="maplayer-editname" name="maplayer-editname" type="text" value="<%= maplayer.name %>">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<label for="maplayer-edittable">Table</label>
<input class="form-control" id="maplayer-edittable" name="maplayer-edittable" type="text" value="<%= maplayer.layertableref %>">
</div>
</div>
<div class="col-sm-4">
<label for="maplayer-editmin">Minimum Zoom</label>
<input class="form-control" id="maplayer-editmin" name="maplayer-editmin" type="number" value="<%= maplayer.minzoom %>">
</div>
<div class="col-sm-4">
<label for="maplayer-editmax">Maximum Zoom</label>
<input class="form-control" id="maplayer-editmax" name="maplayer-editmax" type="number" value="<%= maplayer.maxzoom %>">
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="maplayer-editatt">Attributes to Display:</label>
<textarea class="form-control" rows="3" id="maplayer-editatt" name="maplayer-editatt" ><%= maplayer.layerattributesonclick %></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label for="maplayer-editurl">URL:</label>
<textarea class="form-control" rows="3" id="maplayer-editurl" name="maplayer-editurl" ><%= maplayer.url %></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<p class="text-danger" v-if="cloudError === 'emailAlreadyInUse'">There is already an account using that email address.</p>
<p class="text-danger" v-else-if="cloudError">An error occured while processing your request. Please check your information and try again, or <a href="/contact">contact support</a> if the error persists.</p>
</div>
<div class="col-sm-6">
<div class="form-group text-right">
<button type="button" class="btn btn-warning fontColor" @click="hideAddForm()">Cancel</button>
<ajax-button type="submit" :syncing="syncing" class="btn btn-success">Save changes</ajax-button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</ajax-form>
<% }) %>
I do not know why the input in the maplayers-editlayerid is blank? This is the Layer ID Field. Why is the value=<% maplayer.editlayerid %> not being set?
sails.js
sails.js
asked Nov 15 '18 at 6:35
mblais29mblais29
144118
144118
hmmm I am reading your code and not seeing any typos on your ejs. Maybe your modal? Also just as a note its ALOT easier to read if you camelCase your attributes.editLayerId
– Raqem
Nov 20 '18 at 20:05
add a comment |
hmmm I am reading your code and not seeing any typos on your ejs. Maybe your modal? Also just as a note its ALOT easier to read if you camelCase your attributes.editLayerId
– Raqem
Nov 20 '18 at 20:05
hmmm I am reading your code and not seeing any typos on your ejs. Maybe your modal? Also just as a note its ALOT easier to read if you camelCase your attributes.
editLayerId
– Raqem
Nov 20 '18 at 20:05
hmmm I am reading your code and not seeing any typos on your ejs. Maybe your modal? Also just as a note its ALOT easier to read if you camelCase your attributes.
editLayerId
– Raqem
Nov 20 '18 at 20:05
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313710%2fbind-record-data-to-input-form-values-in-sails-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313710%2fbind-record-data-to-input-form-values-in-sails-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
hmmm I am reading your code and not seeing any typos on your ejs. Maybe your modal? Also just as a note its ALOT easier to read if you camelCase your attributes.
editLayerId
– Raqem
Nov 20 '18 at 20:05