In Razor how do i print some text + a variable value ?
eg :
#for(int i=0;i<5;i++)
{
<input type="text" value="#i" id = "name_#i"/>
}
the above code prints id = "name_#i", but i want the value of i in the id tag.
Try the following:
#for(int i=0;i<5;i++)
{
<input type="text" value="#(i)" id = "name_#(i)"/>
}
When you're having trouble getting Razor to understand your intent, use parenthesis around your expression to create an "Explicit Expression."
One simple way to insert variable in Razor view, insert variable at any where just wrap your variable to (XXX)
<div data-original-title="user" data-toggle="tooltip" data-placement="top" class="#(identifier)completeicon"></div>
<div data-original-title="user" data-toggle="tooltip" data-placement="top" class="comple#(identifier)teicon"></div>
<div data-original-title="user" data-toggle="tooltip" data-placement="top" class="completeicon#(identifier)"></div>
Related
i have two views, view-1 and view-2.
view-1 has form, which will store data temporary.
i want to get data from view-1 and send it to view-2, which has user profile, where temporary data from view-1 will be shown.
how we can achieve it in Laravel, i know we can store data in SQL
and then fetch it, but how to do it without storing to SQL.
my code:
view: 1
<form >
<div class="form-group">
<label class="col-form-label" >Date</label>
<input type="text" name="sdate" class="form-control">
<input type="submit" class="btn btn-primary" value="Add date" >
</div>
</form>
view 2 Controller:
public function report2($id)
{
$teacher = Teacher::teacher($id);
return View('teachers.report2' ,compact('teacher','today','sdate'));
}
Route:
Route::get('teachers/{id}/report2', 'TeachersController#report2');
Use session, for example in view1 you pass variable of date do this on your controller of view 1
session(['sdate' => $request->sdate]);
and then you can get the value of the session in your controller or view by calling this
$date = session('sdate');
further reading see the docs
i was able to do it using simple php;
in view 1 i added this code:
<form action="report2" method="get">
Date: <input type="text" name="today" placeholder="Date of Birth" class="datepicker form-control"><br>
<input type="submit">
</form>
Laravel view 2:
<?php echo $_GET["today"]; ?><br>
i have a little error with my ajax success method DOM elements creation. on the success method i have created an html table row and inside that row i have created a form but this form not work ass expected.
this is a code on ajax success
success: function(data) {
html='';
for (i = 0; i < data['qoutations'].length; i++) {
html+='<tr><form method="post" action="index.php?route=catalog/product/getForm&user_token={{ user_token }}">';
html+='<td class="text-center"><input type="checkbox" name="selected[]" value="'+data['qoutations'][i]['qoutation_id']+'" /></td>';
html+='<td class="text-left">'+data['qoutations'][i]['customer_id'];
html+='<input type="hidden" id="customer_id" value="'+data['qoutations'][i]['qoutation_id']+'"/></td>';
html+='<td class="text-left">'+data['qoutations'][i]['description']+'</td>';
html+='<td class="text-left"> <div class="form-group">';
html+='<textarea class="form-control" rows="2" id="qouted"></textarea>';
html+='</div></td>';
html+='<td class="text-left">';
var customer_id1=data['qoutations'][i]['customer_id'];
var qoutation_id1=data['qoutations'][i]['qoutation_id'];
html+='<input class="btn btn-info" type="submit" id="createproduct" value="Create Product" onClick="createProduct(\'' + customer_id1 + '\',\''+qoutation_id1+'\')"/></td>';
html+='<td class="text-left">'+data['qoutations'][i]['qouted']+'</td>';
html+='<td class="text-left">'+data['qoutations'][i]['status']+'</td>';
html+='<td class="text-left">'+data['qoutations'][i]['date'];
html+='<input type="hidden" id="date" value="'+data['qoutations'][i]['date']+'"/></td>';
html+='<td class="text-left">';
html+='<input class="btn btn-danger" type="button" id="cancel" value="cancel"/></td>';
html+='</tr>';
}
$('#detail').html(html);
}
and this picture elaborate my error. as this picture shows form element open and close immediately.
DOM screenshot
please help, thanks in advance.
The problem with your code is that you are actually not following the standard to create html in your ajax callback.
You can't have a form inside a table row. Only way to do this is to divide your table row into sub form. Please take a look at this question.
HTML: Is it possible to have a FORM tag in each TABLE ROW in a XHTML valid way?
I need to read text value from span tag inside a selected radio button using capyvara
I have a list of radio button followed by text and its count in brackets.
For eg: radiobutton with Thank You(82)
What I want is to read the selected radio button count 82 inside bracket.
I used following code..but it is not working
value=page.find(".cardFilterItemSelection[checked='checked'] + span.itemCount").text
and tried using Xpath but not getting anything
value=page.find(:xpath,"//input[#class = 'cardFilterItemSelection' and #checked = 'checked']/span[#class = 'itemCount']/text()")
How it is possible?
<label id="thankyou_label" for="thankyou_radio" class="itemName radio">
<input checked="checked" tagtype="Occasion" value="Thank You" id="thankyou_radio" name="occasionGroup" class="cardFilterItemSelection" type="radio">
<span class="occasion_display_name">
Thank You
</span>
<span class="itemCount">
(82)
</span>
</label>
<label id="spring_label" class="itemName radio" for="spring_radio">
<input id="spring_radio" class="cardFilterItemSelection" type="radio" name="occasionGroup" value="Spring" tagtype="Occasion">
<span class="occasion_display_name">
Spring
</span>
<span class="itemCount">
(0)
</span>
</label>
I think you were on the right track. But you should have query not for the text node contained by span, but for the span itself and use XPath axes
span = page.find(:xpath,"//input[#class = 'cardFilterItemSelection' and #checked = 'checked']/following-sibling::span[#class = 'itemCount']")
value = span.text
However I personally find css selectors more readable (unless you need to make complex query)
span = page.find(:css, 'input.cardFilterItemSelection[checked=checked] ~ span.itemCount')
value = span.text
i wanna ask something about codeigniter
here is the view
<input class="mws-textinput" name="div_id" type="text" readonly="readonly">
<input class="mws-textinput" name="div_name" type="text" readonly="readonly">
<input id="mws-jui-dialog-mdl-btn" class="mws-button blue small" type="button" value="Show Modal Dialog">
<div id="mws-jui-dialog">
<p><? (**i wanna call the function here**) ?></p>
</div>
here is the function in controller
function dialog(){
$query = mysql_query('select * from tbl_divisi');
while($isi=mysql_fetch_array($query)){
echo '';
}
}
what should i do?
There is two way either you can define this method in model and then call the method of that model in your view file or you can fetch all these values from controller. Here is the detail of how to use model in ci. http://ellislab.com/codeigniter/user-guide/general/models.html
I'm using this tutorial at the moment.
(I believe my issue is related to strongly typed collections... by what I've been seeing on the internet, but I could be wrong)
Please bear with me. :)
I've been having this issue which I asked in another question, the answer seemed fine, but after tinkering with the code a bit more I realized that the issue is that the fields that make use of my custom partial view, don't get a prefix added to them like the fields that use a TextBoxFor html helper, for example. EG. When I click on add a new item, it adds it, but with the same ID as an item that's been added before, then my Javascript fails because there's two items with the same id.
Some code to try and clarify the issue
Partial View
#model Portal.ViewModels.Micros
#using Portal.Helpers
<div class="editorRow" style="padding-left:5px">
#using (Html.BeginCollectionItem("micros"))
{
#Html.EditorFor(model => model.Lab_T_ID)
#Html.EditorFor(model => model.Lab_SD_ID)
#Html.TextBoxFor(model => model.Result)
<input type="button" class="deleteRow" title="Delete" value="Delete" />
}
</div>
The TextBoxFor (Result) gets rendered as
<input id="micros_5e14bae5-df1b-4c42-9e96-573a8e52f8b2__Result" name="micros[5e14bae5-df1b-4c42-9e96-573a8e52f8b2].Result" type="text" value="">
Editor For get rendered as
<select id="Lab_SD_ID" multiple="multiple" style="width: 300px; display: none; " >
<option value="5" selected="selected">Taken at Packing 1</option>
<option value="6">Taken at Packing 2</option>
<option value="7">Taken at Packing 3</option>
</select>
<button type="button" class="ui-multiselect ui-widget ui-state-default ui-corner-all" aria-haspopup="true" tabindex="0" style="width: 300px; ">
<span class="ui-icon ui-icon-triangle-2-n-s"></span><span>Taken at Packing (Winc 4/5-25d)</span></button>
I can include more code if its needed, there is a helper class as well (BeginCollectionItem), that I used which is located in the demo project in the tutorial as well.
I basically need to find out how "micros[5e14bae5-df1b-4c42-9e96-573a8e52f8b2]." gets appended to the input boxes as far as I can see, but have been stumped by it so far :/
The reason this works with TextBoxFor and not your custom EditorFor is because the TextBoxFor helper respects the template navigational context whereas in your editor template you have simply hardcoded a <select> element that doesn't even have a name. I would recommend you to use HTML helpers when generating input fields:
So replace your hardcoded select in the custom template with:
#model int?
#{
var values = ViewData.ModelMetadata.AdditionalValues;
}
<span>
#Html.DropDownList(
"",
Enumerable.Empty<SelectListItem>(),
new {
multiple = "multiple",
style = "width:" + values["comboboxWidth"] + "px",
data_url = Url.Action((string)values["action"], (string)values["controller"]),
data_noneselectedtext = values["noneSelectedText"],
data_value = values["id"],
data_text = values["description"]
}
)
</span>