Dart CheckboxInputElement adds specified text between opening and ending input tags and the browser ignores this text. For example, the following dart code:
FormElement form = new FormElement();
CheckboxInputElement option = new CheckboxInputElement();
option.name = "text1";
option.value = "text1";
option.text = "text1";
form.children.add(option);
window.children.add(form);
creates the following html code:
<form>
<input type="checkbox" name="text1" value"text1">text1</input>
</form>
I end up with checkboxes without descriptors.
You have to add a Label with the descriptor text and link it to the Checkbox:
FormElement form = new FormElement();
CheckboxInputElement option = new CheckboxInputElement();
option.name = "text1";
option.value = "text1";
option.id = "text1";
form.children.add(option);
LabelElement label = new LabelElement();
label.htmlFor = 'text1';
label.text = "This is a checkbox label";
form.children.add(label);
window.children.add(form);
The for property will look for the input with the id specified and connect them (so that clicking on the label text will toggle the checkbox) .
You will end up with the following HTML:
<form>
<input type="checkbox" name="text1" value="text1" id="text1">
<label for="text1">This is a checkbox label</label>
</form>
Related
Will someone kindly give me a hand. Suppose I have a text box and a button. If I type a number say 5 in the text box, I want the numbers 1 to 5 appear in the result text box, one number per line. How should be modifying. Thank you.
<html><head>
<title>Temp proj</title>
<link rel = "stylesheet" type = "text/css"
href = "temp.css">
</head>
<body>
<div class = "container">
<form name = "myform">
<input type = "text" name = "first" class = "mytext" size = "4"><br>
<input class = "button" name = "" value = "Enter" onclick = "enter()"><br>
<input type = "text" name = "result" class = "mytext" size = "4">
</form>
<script type = "text/javascript">
function enter(){
first = parseInt(myform.first.value);
myform.result.value = result;
}
</script>
</head></html>
I updated a Enum Editor I found online to generate kendo radio controls instead of regular but the first radio button is generated with correct attributes and the remaining are wrong and at runtime, the whole set of radio buttons are not clickable
Here is the .cshtml for the editor:
#model Enum
#{
Func<Enum, string> getDescription = en =>
{
Type type = en.GetType();
System.Reflection.MemberInfo[] memInfo = type.GetMember(en.ToString());
if (memInfo != null && memInfo.Length > 0)
{
object[] attrs = memInfo[0].GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.DisplayAttribute), false);
if (attrs != null && attrs.Length > 0)
{
return ((System.ComponentModel.DataAnnotations.DisplayAttribute)attrs[0]).GetName();
}
}
return en.ToString();
};
var listItems = Enum.GetValues(Model.GetType()).OfType<Enum>().Select(e =>
new SelectListItem()
{
Text = getDescription(e),
Value = e.ToString(),
Selected = e.Equals(Model)
});
string prefix = ViewData.TemplateInfo.HtmlFieldPrefix;
int index = 0;
ViewData.TemplateInfo.HtmlFieldPrefix = string.Empty;
foreach (var li in listItems)
{
string fieldName = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}_{1}", prefix, index++);
<div >
#(Html.Kendo().RadioButton()
.Label(li.Text)
.Name(prefix)
.Value(li.Value)
.Checked(li.Selected)
.HtmlAttributes(new { #id = fieldName })
)
#*
This works properly
#Html.RadioButton(prefix, li.Value, li.Selected, new { #id = fieldName, #class = "k-radio" })
#Html.Label(fieldName, li.Text, new { #class = "k-radio-label" })
*#
</div>
}
ViewData.TemplateInfo.HtmlFieldPrefix = prefix;
}
Here is the first radio on the form:
<div>
<input name="StaffType" class="k-radio k-radio" id="StaffType_0" type="radio" checked="checked" value="DACStaff" data-val-required="The StaffTypeEnum field is required." data-val="true">
<label class="k-radio-label" for="StaffType_0_DACStaff">DAC Staff</label>
</div>
And here is the next one:
<div>
<input name="StaffType" class="k-radio k-radio" id="StaffType_1" type="radio" value="AirportStaff">
<label class="k-radio-label" for="StaffType_1_AirportStaff">Airport Staff</label>
</div>
I see that the class tag k-radio is applied twice and except the first element has the data-* attributes but second radio button and onwards, the generated code is missing attributes.
Can someone point out why the generated code is not functioning?
Usage:
<div class="form-group">
#Html.LabelFor(m => m.StaffType, new { #class = "col-sm-3 control-label" })
<div class="col-sm-6">
#Html.EditorFor(m => m.StaffType, "RadioButtonListEnum")
</div>
</div>
If click the submit button or a-element then automatically the input text is clicked.
function send()
{
var txt = document.getElementById("textbox");
txt.click();
}
<input type="text" id="textbox" name="textbox" style="width:90%;">
<a id="send" style="display:none;" onclick="send()" href="">Send</a>
If you want to get the value of "textbox" with the following instruction:
var txt = document.getElementById("textbox");
Then you need to correct it like this:
var txt = document.getElementById("textbox").value;
I'm having trouble passing my textbox data to a controllers action parameters.
I'm trying to get the url to look like:
http://localhost:51124/gifts?searchTerm=test
but when I enter in text into the text box I get a url that looks like:
http://localhost:51124/gifts
Here is the code I have for the route:
routes.MapRoute("Gifts",
"gifts",
new { controller = "Gifts", action = "Search" });
here is the code for the page with the text box and button to submit the text box data:
<form method="GET">
<input type="search" name="searchTerm"/>
<input type="button" value="Search By Category" onclick="location.href='#Url.Action("Search", "Gifts")'" />
</form>
here is the code for the controller that I'm trying to pass data to unsuccessfully:
public ActionResult Search(string searchTerm = null)
{
var model = db.Gifts.ToList();
return View(model);
}
"searchTerm" never gets any parameter that I pass into the text box. It's always null.
Create a form element in you view with an input (i.e. the search box) that has a name attribute matching the parameter and a submit button.
#using (Html.BeginForm("Search", "Gifts") {
<input type='text' name='searchTerm' value='' />
<input type='submit' value='search' />
}
This will post back to the Search method in the Gifts controller, passing the vale of the search box to the parameter 'searchTerm'
you have to build this with jquery. add a class to the inputs to use as a selector
<input type="search" name="searchTerm" class="txtSearch" />
<input type="button" value="Search By Category" class="btnSearch" />
then in your script
$('.btnSearch').on('click', function(){
var url = '#Url.Action("Search", "Gifts", new { searchTerm = "----" })'.replace("----", $('.txtSearch').val());
window.location(url);
});
I use <input type="file" id="fileId" name="fileId"/> and
<% = Html.TextBoxFor (x => x.FileName, new {# class = "className", maxlength = 255, id = "fileName"})%> in my mvc project. I want to save in a text box the file name selected in the INPUT element. How can I do this?
You need to use javascript to achieve this. Here's an example with jquery:
$(function() {
$('#fileId').change(function() {
// When the user selects a file, read the selected filename
// and set it to the textbox
var filename = $(this).val();
$('#fileName').val(filename);
});
});