Sitecore not pulling through field values - sitecore

Instead of the field value coming through I get 'No text in the field'. This is for all views that reference a field and isn't hard coded seemingly.
The content is there in the content editor, but not pulling through to the experience editor or the live web view. I've tried rebuilding the link databases, as well as using the GUID in the view to reference the field but no luck fixing this.
For example:
Local
Experience Editor on local
Content editor on local
Live
Experience Editor on live
#using Sitecore.Mvc
#using Sitecore.Data.Items
#using Sitecore.Mvc.Presentation
#model RenderingModel
#{
int counter = 0;
int maxvisible = 6;
// Count can be set in the control properties so the editors can vary the amount of cards showing
if (Html.Sitecore().CurrentRendering.Parameters["Count"] != null)
{
maxvisible = int.Parse(Html.Sitecore().CurrentRendering.Parameters["Count"]);
}
var UniqueName = "";
if (Html.Sitecore().CurrentRendering.Parameters["UniqueName"] != null)
{
UniqueName = Html.Sitecore().CurrentRendering.Parameters["UniqueName"];
}
var cardpanel = "cardpanel" + UniqueName;
UniqueName = "expandbutton" + UniqueName;
Item firstChild = Model.Item.Children[0];
}
<!--Adaptive code (as opposed to Responsive)-->
<!--html code for desktop version-->
<div class="container visible-lg visible-md visible-sm">
<div class="row row-eq-height">
#foreach (Item child in Model.Item.Children)
{
if (#Html.Sitecore().Field("ExcludeFromPage", child).ToString() != "1")
{
if (counter >= maxvisible)
{
if (counter == maxvisible)
{
#:<div class="#cardpanel" style="display: none;">
#:<div class="row-eq-height">
}
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4 CardHeightMargin flexbox">
<div class="rcorners1">
<div class="col-xs-12 img-padding cardmobile top">
<div class="#Html.Sitecore().Field("{C63983F3-6ECD-45EA-A1D5-DFB37B366EDD}", child) scale-08"></div>
</div>
<div class="col-xs-12 CardHeight cardmobile bottom">
<h3>#Html.Sitecore().Field("{5787E6DD-A0F2-454F-AC4C-50921D4BBCB3}", child)</h3>
<p>#Html.Sitecore().Field("{1E900F2F-6F68-46B4-A98A-7BDF3CE06C5E}", child)</p>
</div>
</div>
</div>
}
else
{
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4 CardHeightMargin flexbox">
<div class="rcorners1">
<div class="col-xs-12 img-padding cardmobile top">
<div class="#Html.Sitecore().Field("{C63983F3-6ECD-45EA-A1D5-DFB37B366EDD}", child) scale-08"></div>
</div>
<div class="col-xs-12 CardHeight cardmobile bottom">
<h3>#Html.Sitecore().Field("{5787E6DD-A0F2-454F-AC4C-50921D4BBCB3}", child)</h3>
<p>#Html.Sitecore().Field("{1E900F2F-6F68-46B4-A98A-7BDF3CE06C5E}", child)</p>
</div>
</div>
</div>
}
counter++;
}
}
#if (counter != 0 && counter > maxvisible)
{
#:</div>
#:</div>
<div class="center-block #UniqueName">
#Html.Sitecore().Field("Expand")
</div>
}
</div>
</div>
<!--html code for mobile version - Carousel-->
<div class="container visible-xs">
<div id=#Model.Item.Children[0].ID.Guid.ToString("N") class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="##Model.Item.Children[0].ID.Guid.ToString("N")" data-slide-to="0" class="active"></li>
#for (int itemcount = 1; itemcount < Model.Item.Children.Count; itemcount++)
{
<li data-target="##Model.Item.Children[0].ID.Guid.ToString("N")" data-slide-to=#itemcount></li>
}
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner m-y-1" role="listbox">
<div class="item mobilecardheight active">
<div class="col-xs-12 img-padding img-div-height">
<div class="#Html.Sitecore().Field("{C63983F3-6ECD-45EA-A1D5-DFB37B366EDD}", firstChild) scale-08"></div>
</div>
<div class="col-xs-12 CardHeight ">
<h3>#Html.Sitecore().Field("{5787E6DD-A0F2-454F-AC4C-50921D4BBCB3}", firstChild)</h3>
<div class="col-xs-12">
<p>#Html.Sitecore().Field("{1E900F2F-6F68-46B4-A98A-7BDF3CE06C5E}", firstChild)</p>
</div>
</div>
</div>
#foreach (Item child in Model.Item.Children)
{
if (child.ID != firstChild.ID)
{
if (#Html.Sitecore().Field("ExcludeFromPage", child).ToString() != "1")
{
<div class="item mobilecardheight">
<div class="col-xs-12 img-padding img-div-height">
<div class="#Html.Sitecore().Field("{C63983F3-6ECD-45EA-A1D5-DFB37B366EDD}", child) scale-08"></div>
</div>
<div class="col-xs-12 CardHeight">
<h3>#Html.Sitecore().Field("{5787E6DD-A0F2-454F-AC4C-50921D4BBCB3}", child)</h3>
<div class="col-xs-12">
<p>#Html.Sitecore().Field("{1E900F2F-6F68-46B4-A98A-7BDF3CE06C5E}", child)</p>
</div>
</div>
</div>
}
}
}
<!-- Left and right controls -->
<a class="left carousel-control" href="##Model.Item.Children[0].ID.Guid.ToString("N")" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="##Model.Item.Children[0].ID.Guid.ToString("N")" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
<!--More button javascript used on the desktop screens-->
#if (counter != 0 && counter > maxvisible)
{
<script>
var acc = document.getElementsByClassName("#UniqueName");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function () {
var panel = this.previousElementSibling;
if (panel != null) {
if (panel.style.display === "block") {
panel.style.display = "none";
this.innerHTML = "<a href='#policies' class='more_link'>Show more</a>";
} else {
panel.style.display = "block";
this.innerHTML = "<a href='#policies' class='more_link'>Show less</a>";
}
}
});
}
</script>
}
This was all working as expected on my local, but I must've changed something elsewhere that caused this. Any ideas?

Can you please add some more Screen shot? am not getting what content you exactly added in content editor.

Your field references look strange to me...
#Html.Sitecore().Field("{5787E6DD-A0F2-454F-AC4C-50921D4BBCB3}", child)
The parameters for #Html.Sitecore().Field() are:
string FieldName
string FieldName, Item item
string FieldName, object parameters
string FieldName, Item item, object parameters
Are your fields literally called "{5787E6DD-A0F2-454F-AC4C-50921D4BBCB3}" or is that just their ID? Your editor screenshot has the fields "CardText", "CardTitle", "CardIcon" and that's what I'd expect to see used instead of the GUIDs:
#Html.Sitecore().Field("CardTitle", child)
No idea why it'd be working on live though if what you showed is also what's deployed.

Related

Django template is rendering in Multi-step form, but context data is not visible

I am working on this problem and somehow resolved it to a very great extent and almost everything is done. But the Django is rendering my template but not the Context.
I don't know why I have checked it by debugging and my context is rendering but not showing in frontend.
On this template, there is a form with 4 fieldset , I am submitting data in 1st fieldset and the dynamically show o/p accordingly on the second fieldset.
I am attaching screenshot to show what is rendering in template(2nd fieldset)
edit:
I have debugged this and in code all is working fine but it is not showing up in fornt-end, I dont know why
#views.py
def createQuotePage(request):
if request.method == "POST":
# Getting all the value
# saving in Table
saveInUnitsTable(-------some code, removed to shorten question ------)
saveInCustomerTable(-------some code, removed to shorten question ------)
saveInInquiryTable(-------some code, removed to shorten question ------)
flight_suggestions =Flight.objects.filter(sourceairportid=1,destinationairportid=51)
context = {'flight_suggestions':flight_suggestions,"test":"99999999999999999999999999999999999999"}
return render(request,"Freight/create_quote.html",context=context) # <-- here is the PROBLEM
if request.method == "GET":
print("========================GET=======================")
context = {'airport_data' : list(Airport.objects.all()),
'commodity_data':list(Commodity.objects.all()),
'customerType_data':list(Entity.objects.all()),
}
return render(request,"Freight/create_quote.html",context=context)
#scripts.js
(function($) {
"use strict";
$.backstretch;
$('#top-navbar-1').on('shown.bs.collapse', function(){
$.backstretch("resize");
});
$('#top-navbar-1').on('hidden.bs.collapse', function(){
$.backstretch("resize");
});
$('.f1 fieldset:first').fadeIn('slow');
$('.f1 .btn-next').on('click', function() {
//
var parent_fieldset = $(this).parents('fieldset');
var next_step = true;
var current_active_step = $(this).parents('.f1').find('.f1-step.active');
var progress_line = $(this).parents('.f1').find('.f1-progress-line');
//
var formData1 = $("#total-shipment-form").serialize();
var formData2 = $("#units-form").serialize();
var formData3 = $("#customerDetailForm").serialize();
var formData4 = $("#firstFieldset").serialize();
var formData = formData1 + '&' +
formData2 + '&' +
formData3 + '&' +
formData4
$.post("",formData)
.done(function(){
//
console.log('Success : ');
// var parent_fieldset = $(this).parents('fieldset');
// var next_step = true;
// var current_active_step = $(this).parents('.f1').find('.f1-step.active');
// var progress_line = $(this).parents('.f1').find('.f1-progress-line');
if( next_step ) {
parent_fieldset.fadeOut(400, function() {
current_active_step.removeClass('active').addClass('activated').next().addClass('active');
bar_progress(progress_line, 'right');
$(this).next().fadeIn();
scroll_to_class( $('.f1'), 20 );
});
}
//
})
.fail(function(){
console.log('Error : ');
});
});
Edited:-
Html template
<fieldset id="secondFieldset">
<div class="form-group select_all_style">
<input class="form-check-input" type="checkbox" value=""
id="select_all">
<label for="select_all" class="font-bold lh-26 fs-14">Select All</label>
</div>
{{test}}
<div class="airline_wrapper check_box_wrapper">
{{test}}
{% for flight in flight_suggestions %}
<div class="col_2 text-center dhl_text ">
<div class="aviation_wrapper">
<div class="aviation_checkbox">
<input class="form-check-input" type="checkbox" value=""
id="flexCheckDefault">
</div>
<div class="d-inline pl_10">
<!-- <p>Expiry Date <span><b>6 Sep 2022</b></span></p> -->
<h4 class="fw-400 fs-28">{{flight.flightcompany}}</h4>
<p>Air Freight</p>
</div>
</div>
</div>
<div class="col_6">
<div class="flight_container text-center">
<i class="fa-solid fa-plane plane_style"></i>
<div class="flight_details"></div>
<div class="flight_content">
<div>
<h4>{{flight.sourceairportid.airportname}}</h4>
<p>{{flight.sourceairportid.cityid.cityname}}</p>
</div>
<div>
<h4>{{flight.destinationairportid.airportname}}</h4>
<p>{{flight.destinationairportid.cityid.cityname}}</p>
</div>
</div>
<hr>
<div class="d-flex">
<div class="flight_sub_text text-left">
<label for="">Transit Time</label>
<h5>-- Hrs</h5>
<h5>{{flight.trasittime}} Hrs</h5>
</div>
</div>
</div>
</div>
<div class="col_3">
<h4 class="text-center reference_text">Past Reference</h4>
<div class="buy_text_wrapper">
<p>Buy Rate</p>
<p>Sell Rate</p>
</div>
<div class="buy_text_wrapper">
<p>USD 5,500.00</p>
<p>USD 7,000.00</p>
</div>
<h5 class="probabilty_text text-center pt-4"><span><i
class="fa-solid fa-arrow-trend-up"></i> 70%</span>
Winnning Probabilty</h5>
</div>
{% endfor %}
</div>
<div class="f1-buttons">
<button class="btn btn-primary btn-next" type="button">Request Better
Rates</button>
</div>
</fieldset>

Call google.script.run from HTMLService Template

When i try execute comand
var obj = google.script.run.receitaws(cnpj);
from custom html template form didin't work, return Undefined, but when run this function by spreadsheets work's.
I will post my project below:
I combine many html files to create html struture form.
To join files i use the function include(file)
function include(File) {
var template = HtmlService.createTemplateFromFile(File).evaluate();
Logger.log(template.getContent());
return HtmlService.createHtmlOutput(template.getContent()).getContent();
}
To call my custom html template by function openlink
function openlink() {
var template = HtmlService.createTemplateFromFile('tabs')
.evaluate()
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(650);
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog(template, 'Form');
}
File tabs is a html template file
<?!= include('before')?>
<ul id="tabs-form-servico" class="tabs">
<li id="tbulli1" class="tab col s2"><a class="" href="#tab1">1 - Tomador do Serviço</a></li>
<li id="tbulli2" class="tab col s2"><a class="active" href="#tab2">2 - Prestador do Serviço</a></li>
<li id="tbulli3" class="tab col s2 hide">3 - Serviço Executado</li>
<li id="tbulli4" class="tab col s2 hide">4 - Regras Retenção Municipal</li>
<li id="tbulli5" class="tab col s2 hide">5 - Regras Retenção Previdenciario</li>
<li id="tbulli6" class="tab col s2 hide">6 - Regras Retenções Federal</li>
<li id="tbulli7" class="tab col s2 hide">7 - Cálculo Retenções</li>
<li id="tbulli8" class="tab col s2 hide">8 - Pagamento</li>
</ul>
<div id="tab1" class="col s12">Criar</div>
<div id="tab2" class="col s12"><?!= include('prestadorservico')?></div>
<div id="tab3" class="col s12">Teste bem sucedido</div>
<div id="tab4" class="col s12"></div>
<div id="tab5" class="col s12"></div>
<div id="tab6" class="col s12"></div>
<div id="tab7" class="col s12"></div>
<div id="tab8" class="col s12"></div>
<script>
$(document).ready(function(){
$('#tabs-form-servico').tabs({'swipeable': true });
Materialize.updateTextFields();
});
function close() {
google.script.host.close()'
}
</script>
<?!= include('after')?>
File before is a html template file also
<!DOCTYPE html>
<html>
<head>
<base target="_blank">
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" media="screen,projection">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
File after is a html template file also
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.10/jquery.mask.min.js"> </script>
<script>
$(document).ready(function() {
$('select').material_select();
$('.tooltipped').tooltip({delay: 50});
});
</script>
</body>
</html>
The problem is here in html template file prestadorservico
<div class="row">
<form class="col s12">
<div class="row">
<div class="input-field col s3">
<input id="cnpj" type="text" class="validate" autofocus>
<label for="cnpj">CNPJ</label>
</div>
<div class="input-field col s1">
<a class="btn-floating tooltipped rounded" onclick="consultacnpj()" data-tooltip="Preenchimento Automático da RF"><i class="material-icons">refresh</i></a>
</div>
<div class="input-field col s8">
<input placeholder="Prestador LTDA" id="contratado_nome" type="text" class="validate">
<label for="contratado_nome">Nome do Contratado</label>
</div>
</div>
<div class="row">
<div class="input-field col s10">
<input value="" id="address" type="text" class="validate">
<label for="address">Endereço</label>
</div>
<div class="input-field col s2">
<input value="" id="number" type="text" class="validate">
<label for="number">Número</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<input value="" id="compl" type="text" class="validate">
<label for="compl">Complemento</label>
</div>
<div class="input-field col s6">
<input value="" id="bairro" type="text" class="validate">
<label for="bairro">Bairro</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<?!= include('cidades');?>
</div>
<div class="input-field col s6">
<input value="" id="cep" type="text" class="validate">
<label for="cep">CEP</label>
</div>
</div>
<div class="row">
<div class="input-field col s7">
<input id="email" type="email" class="validate">
<label for="email" data-error="wrong" data-success="right">Email</label>
</div>
<div class="input-field col s5">
<input id="phone" type="text" class="validate">
<label for="phone">Telefone</label>
</div>
</div>
<div class="row">
<div class="input-field col s12 m6">
<input value="" id="cnaep" type="text" class="validate">
<label for="cnaep">CNAE Principal</label>
</div>
<div class="input-field col s12 m6">
<input value="" id="cnaes" type="text" class="validate">
<label for="cnaes">CNAE Secundários</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<select>
<option value="" disabled selected>Escolha sua opção</option>
<option value="1">Pessoa Física</option>
<option value="2">MEI - Micro Empreendedor Individual</option>
<option value="3">Imunes/Isentas</option>
<option value="4">Cooperativa de Trabalho</option>
<option value="5">Simples Nacional</option>
<option value="6">Lucro Real/Presumido</option>
</select>
<label>Regime Tributário</label>
</div>
<div class="container col s3 offset-s3">
<a class="btn-large waves-effect waves-light right" id="btnnext2" onclick="nextstep()" name="next">Next
<i class="material-icons right">send</i>
</a>
</div>
</div>
</form>
</div>
<div class="divider"> </div>
<?!= include('SimplesReceitaFederal')?>
<script>
function nextstep() {
$('#tbulli3').removeClass('hide');
$('#tabs-form-servico').tabs('select_tab', 'tab3');
}
function consultacnpj(){
var cnpj = $('#cnpj').val().toString();
if (cnpj.length==14){
var obj = google.script.run.receitaws(cnpj); //here i have a problem
$('#contratado_nome').val(obj);
$('#address').val(obj.logradouro);
$('#number').val(obj.numero);
$('#compl').val(obj.complemento);
$('#bairro').val(obj.bairro);
$('#cep').val(obj.cep);
$('#city').val((obj.municipio + '/' + obj.uf))
var code = google.script.run.codeCNAE(obj.atividade_principal[0].code);
$('#cnaep').val((code + ' - ' + obj.atividade_principal[0].text));
var codes = google.script.run.CNAESecundarios(obj.atividades_secundarias);
$('#cnaes').val(codes);
} else {
Materialize.toast('Preencha um CNPJ valido.', 3000)
}
}
</script>
File cidades is a html template file
<? var data = SpreadsheetApp
.openById('my_id_Sheet')
.getSheetByName('Municipios')
.getRange(3, 4, 5575)
.getValues(); ?>
<select>
<option value="" disabled selected>Escolha a Cidade/UF</option>
<? for (var i = 0; i < data.length; i++) { ?>
<option value="<?!= i ?>"><?!= data[i] ?></option>
<? } ?>
</select>
<label>Cidade/UF</label>
Function.gs codeCNAE()
function codeCNAE(cod){
cod = cod.replace('.', '');
var cods = cod.split('-');
cod = cods[0]+'-'+cods[1]+'/'+cods[2];
return cod;
}
Function.gs CNAESecundarios()
function CNAESecundarios(obj){
var i, codes = "";
for (i in obj) {
if (codes == '') {
codes = '{' + codeCNAE(obj[i].code)
} else {
codes = codes + ', ' + codeCNAE(obj[i].code)
}
codes = codes + ' - ' + obj[i].text
}
codes = codes + '}'
//Logger.log(codes);
return codes;
}
Function.gs receitaws()
function receitaws(cnpj) {
Utilities.sleep(Math.random() * 1000);
var token = "my_id_token";
var url, response, obj;
url = 'http://receitaws.com.br/v1/cnpj/'
+ cnpj;
response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true});
obj = JSON.parse(response);
if (obj.status == "ERROR" && obj.message !="CNPJ inválido") {
Logger.log('Versão Paga');
url = 'https://receitaws.com.br/v1/cnpj/'
+ cnpj
+ "/days/0";
response = UrlFetchApp.fetch(url, {'muteHttpExceptions': true, 'headers': {'Authorization': 'Bearer ' + token}});
obj = JSON.parse(response);
}
return obj;
}
I discovered my problem. In this case I need to run a
.withSuccessHandler(onSuccess)
to get a function return called.
I tried this and it worked.
I change my function consultacnpj() in file prestadorservico
function consultacnpj(){
var cnpj = $('#cnpj').val().toString();
if (cnpj.length==14){
google.script.run
.withSuccessHandler(onSuccessCNPJ)
.withFailureHandler(onFailureCNPJ)
.receitaws(cnpj);
function onFailureCNPJ(error) {
Materialize.toast("ERROR: " + error.message, 3000)
}
function onSuccessCNPJ(obj) {
$('#contratado_nome').val(obj.nome);
$('#address').val(obj.logradouro);
$('#number').val(obj.numero);
$('#compl').val(obj.complemento);
$('#bairro').val(obj.bairro);
$('#cep').val(obj.cep);
$('#city').val((obj.municipio + '/' + obj.uf))
var code = google.script.run
.withSuccessHandler(onSuccessCNAEP)
.withFailureHandler(onFailureCNAEP)
.codeCNAE(obj.atividade_principal[0].code);
function onFailureCNAEP(error) {
Materialize.toast("ERROR: " + error.message, 3000)
}
function onSuccessCNAEP(code) {
$('#cnaep').val(code + ' - ' + obj.atividade_principal[0].text);
};
google.script.run
.withSuccessHandler(onSuccessCNAES)
.withFailureHandler(onFailureCNAES)
.CNAESecundarios(obj.atividades_secundarias);
function onFailureCNAES(error) {
Materialize.toast("ERROR: " + error.message, 3000)
}
function onSuccessCNAES(codes) {
$('#cnaes').val(codes);
}
Materialize.updateTextFields();
Materialize.updateTextFields();
}
} else {
Materialize.toast('Preencha um CNPJ valido.', 3000)
}
}
If anyone have a other tip, please post it.
I'm still learning google-apps-script and javascript.
Thanks!

Django append +1 in template

I have modal that displays uploaded images from ExamFile model that is foreign-key connected to Exam model. In order for lightbox galerry to work i need to specify slide number of each examfile picture, so i need to append 1 for every picture (probably in template?)
i have this script:
{% for file in exam.examfile_set.all %}
<div class="row">
<div class="column">
<img src="{{file.exam_file.url}}" width=60 height="60"
onclick="openModal();currentSlide(//this is where i need to append +1 for every file in exam.examfile_set.all //)"
class="hover-shadow cursor">
</div>
{% endfor %}
<div id="myModal" class="modal">
<span class="close cursor" onclick="closeModal()">×</span>
<div class="modal-content">
{% for file in exam.examfile_set.all %}
<div class="mySlides">
<div class="numbertext">1 / 4</div>
<img src="{{file.exam_file.url}}" style="width:100%">
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
<div class="caption-container">
<p id="caption"></p>
</div>
</div>
</div>
</div>
<script>
function openModal() {
document.getElementById('myModal').style.display = "block";
}
function closeModal() {
document.getElementById('myModal').style.display = "none";
}
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
var captionText = document.getElementById("caption");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
captionText.innerHTML = dots[slideIndex-1].alt;
}
</script>
{% endfor %}
i have posted full code but my problem is in 5th notempty row. Thanks in advance!
You can use built-in forloop.counter variable:
{% for file in exam.examfile_set.all %}
<div class="row">
<div class="column">
<img src="{{ file.exam_file.url }}" width=60 height="60"
onclick="openModal();currentSlide({{ forloop.counter }})"
class="hover-shadow cursor">
</div>
{% endfor %}
More info in the docs: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for.

iOnic list not refreshing after adding a new item to the list using web service

We have a iOnic based project and during check out users can add new address to their account.
This is what my controller file look like
$scope.addAddress = function() {
$scope.showLoading();
addressService.addUserAddress($scope.userDetails.userID, $scope.addAddressdata.houseNo, $scope.addAddressdata.street, $scope.addAddressdata.AddDesc, $scope.addAddressdata.LID)
.success(function(response) {
console.log(response);
$scope.hideLoading();
$scope.closeModal();
$scope.getAllAddress();
});
};
$scope.getAllAddress = function() {
addressService.getAllLocations()
.success(function(response) {
$scope.locations = response;
$scope.hideLoading();
});
};
And this is what my services file look like
function() {
"use strict";
var myApp = angular.module('jobolo');
myApp.service('addressService', ['$http', 'appVariableService', function($http, appVariableService) {
var addressService = this;
addressService.getAllLocations = function() {
var data = {
appid: appVariableService.get('appId')
};
return $http.post(appVariableService.get('baseURL') + 'useraddress/getMyLocation', data);
};
addressService.getUserAddress = function(userId) {
return $http.get(appVariableService.get('baseURL') + 'useraddress/myaddress/' + userId, {cache:false});
};
addressService.addUserAddress = function(userId, houseNo, street, adddesc, lid) {
var data = {
appid: appVariableService.get('appId'),
userid: userId,
houseno: houseNo,
street: street,
adddesc: adddesc,
lid: lid,
};
return $http.post(appVariableService.get('baseURL') + 'useraddress/adAdd' , data);
};
}]);
})();
When I add a new address it does add to the database but isn't showing in list. I tried adding $scope.refreshList(); to the code too. When I log out and come back it does show up. Thank you for your help in advance
View Codes are
<ion-view class="main-content">
<ion-nav-buttons side="secondary">
<button menu-toggle="right" class="button button-icon icon ion-navicon"></button>
</ion-nav-buttons>
<div class="bar bar-subheader">
<h2 class="title">Select Address</h2>
</div>
<ion-content class="has-subheader" scroll="true" overflow-scroll="true" style="bottom:57px">
<div class="list">
<ion-radio
ng-model="data.selectedAddress"
ng-value="address"
ng-repeat="address in userAddresses"
class="radio-nowrap"
>
House No. {{address.HouseNo}}, {{address.Street}}, {{address.AddDesc}}, {{address.AreaName}}, {{address.City}}
</ion-radio>
</div>
<!-- <div class="row">
<div class="col location-form">
<button class="button" type="button" ng-click="openModal()">Add New Address</button>
</div>
</div> -->
</ion-content>
<div class="row" style="position: absolute;bottom: 0;padding:0">
<div class="col location-form">
<button class="button" type="button" ng-click="openModal()">Add New Address</button>
</div>
<div class="col location-form">
<button class="button" type="button" ng-disabled="!data.selectedAddress" ng-click="selectAddress(data.selectedAddress)">Select Address</button>
</div>
</div>

{{bindAttr }} {{action}} [Object] Has no method replace

when ember.js tries to render my template containing the following bindAttr. the following exception is thrown in handlebars.js
Uncaught TypeError: Object [object Object] has no method 'replace' handlebars.js:848
bind attr tag:
<div class="postWrapper" {{bindAttr style="display:none"}}>
Update
this also happens when i use the action helper
<div {{action Toggle}} class="btn pull-right">
<i class="postToggler icon-chevron-down " ></i>
</div>
Update Full Code
Template
<script type="text/x-handlebars" data-template-name="Composer">
<div class="postWrapper">
<div class="postContentWrapper" {{bindAttr style="controller.display"}}>
<div class="row-fluid">
<div class="pull-left span10">
To :
<input id="test2" type="text" style="margin-top: 7px;width:90%" />
</div>
<div {{action Toggle}} class="btn pull-right">
<i class="postToggler icon-chevron-down " ></i>
</div>
</div>
<div class="row-fluid" style="height:100%" >
<div id="wmd-button-bar" style="width:48%;display:inline-block" ></div>
<div class="pull-right">
<a>Hide preview</a>
</div>
<div class="wmdWrapper" style="height:80%">
<div class="wmd-panel" style="vertical-align: top;">
<textarea class="wmd-input" id="wmd-input" style="height: 100%;"></textarea>
</div>
<div id="wmd-preview" class="wmd-preview pull-right"></div>
</div>
<br />
</div>
<div class="row-fluid">
<div class="span6 ">
<p>
Tags :
<input id="test" type="text" style="width:80%"/>
</p>
</div>
<div class="span2 pull-right">
<button id="btnSubmitPost" class="btn btn-success pull-right">{{controller.buttonText}}</button>
<button id="btnCanelPost" class="btn btn-warning pull-right">Cancel</button>
</div>
</div>
<div class="row-fluid">
</div>
</div>
</div>
</script>
View and render
/*
MODES
NEW
REPLY
*/
Thoughts.ComposerController = Ember.Object.extend({
mode: 2,
visible: false,
messageContent: "",
buttonText: function () {
switch (this.get("mode")) {
case 1: return "Post";
case 2: return "Reply";
}
}.property(),
display: function () {
if (this.get("visible")) {
return 'display:block';
} else
return 'display:none';
}.property(),
Toggle: function(){
console.log('Helllo');
}
});
Thoughts.ComposerController = Thoughts.ComposerController.create();
Error Information
object dump
string: "data-ember-action="1""
__proto__: Object
constructor: function (string) {
toString: function () {
__proto__: Object
Crashes on the replace method, because the method replace is undefined
Handlebars.Utils = {
escapeExpression: function (string) {
// don't escape SafeStrings, since they're already safe
if (string instanceof Handlebars.SafeString) {
return string.toString();
} else if (string == null || string === false) {
return "";
}
if (!possible.test(string)) { return string; }
----> return string.replace(badChars, escapeChar);
},
So first of all you need to define only need to define the controller. You don't have to create an instance. Ember will do it for you when application initialize.
If you define a property that is observing another in other words its value depends on another, you need this to specify as parameter to property helper.
Thoughts.ComposerController = Ember.Controller.extend({
mode: 2,
visible: false,
messageContent: "",
buttonText: function () {
switch (this.get("mode")) {
case 1: return "Post";
case 2: return "Reply";
}
}.property('mode'),
display: function () {
return 'display:' + this.get('visible') ? 'block' : 'none';
}.property('visible'),
Toggle: function () {
this.toggleProperty('visible');
this.set('mode', this.get('mode') == 2 ? 1 : 2);
}
});
Template itself seems valid.
You can get this working by creating a composer route like this:
this.route('composer');
or by rendering it in another template like this:
{{render 'composer'}}
That should be answer to your question. BUT
Wouldn't be better to use {{if}} helper for showing some content inside of template based on a condition?
i finally found some time to work on this again.
all i did was replace the ember and handlebars js files, and the code is working fine now thanks