I am trying to convert an #Html.Textbox image button to submit button with the onclick calling a Javascript function but I can't seem to figure out the validation part. I believe it does need to be a submit button.
I am basically trying to get rid of the image but keep the functionality.
Here's what's working today.
#Html.TextBox("Next", null, new {type = "image", src = #Url.Content("../App_Themes/icons/button_next.png"), #class = "imgbottom", onclick = "javascript: ValidateSelection ($(\"[name$='selectedItems']:checked\"))"})
function ValidateSelection(item) {
if (item == null || item.length == 0) {
var validationSummary = $('.validation-summary-errors ul');
if (validationSummary.length > 0 && $('.validation-summary-errors ul li').length == 0) {
validationSummary.append('<li>' + "Please select at least one item" + '</li>');
}
var errors = $("[name='ErrorMessage']");
if (errors.length > 0) {
errors.hide();
}
var buttonGenerateReport = $("#GenerateReport");
if (buttonGenerateReport.length > 0) {
buttonGenerateReport.hide();
}
event.preventDefault();
}
}
<button type="submit" class="imgbottom" onclick="ValidateSelection('selectedItems');">
<img src="#Url.Content("~/App_Themes/icons/button_next.png")" alt="Next" /><br />
Next
</button>
The "~/" part of the Url Content string represents your project root, so adjust it to fit your correct file address later.
Or you could just use FontAwesome and replace your image entirely by that. It's size scalable because of CSS and has a simpler syntax.
<button type="submit" class="imgbottom" onclick="ValidateSelection('selectedItems');">
<i class="fa fa-angle-double-right" aria-hidden="true"></i> Next
</button>
Then in your jQuery function:
function ValidateSelection(elementName){
var selectedItems = $("[name='" + elementName + "']:checked");
if (selectedItems === null || selectedItems.length === 0) {
var validationSummary = $('.validation-summary-errors ul');
if (validationSummary.length > 0 && $('.validation-summary-errors ul li').length == 0) {
validationSummary.append('<li>' + "Please select at least one item" + '</li>');
}
var errors = $("[name='ErrorMessage']");
if (errors.length > 0) {
errors.hide();
}
var buttonGenerateReport = $("#GenerateReport");
if (buttonGenerateReport.length > 0) {
buttonGenerateReport.hide();
}
event.preventDefault();
}
}
Related
I am trying to refresh a bootstrap 3.0 multiselect control.
On refresh, I want to reset the checkboxes to its previous state when the partial view was first rendered
How can I achieve that?
I tried following approach but didn't get success.
Maintained hidden field for storing selected checkbox values once view
was rendered.
On Reset button click:
2.1 Uncheck all checkboxes.
2.2 Check only those checkboxes whose value I got from hidden field.
j('#btnReset11').click(function () {
j("#divErrorMessage ul li").not(':first').remove();
j("#divErrorMessage").hide();
j("#divSuccessMessage").hide();
j("#includeSelectAllOption").find("option").removeAttr("selected");
j("#chkRoles ul li").removeClass("active");
j("#chkRoles .btn-group").find("button").removeAttr('title');
j("#chkRoles .btn-group").find("button").text('Select');
var value = j("#selectedCheckboxes").val();
valueItems = value.split(", ");
for (var i = 0; i < valueItems.length; i++) {
j('#' + valueItems[i]).attr('selected', 'selected');
j("#chkRoles ul li input[value=" + valueItems[i] + "]").parent().parent().parent().addClass("active");
var title = j("#chkRoles .btn-group").find("button").title;
j("#chkRoles .btn-group").find("button").removeAttr(title);
}
if (valueItems.length > 0) {
j("#chkRoles .btn-group").find("button").text(valueItems.length + ' selected');
}
else {
j("#chkRoles .btn-group").find("button").text('Select');
}
});
j(document.body).on('click', '#btnReset-Button', function () {
j("#divErrorMessage").hide();
j(this).parents('.PopupModalClass').find('input[type="text"],input[type="email"],select').each(function () {
if (this.defaultValue != '' || this.value != this.defaultValue) {
this.value = this.defaultValue;
setTimeout(function () {
j('.PopupModalClass #multiSelectDropdown').multiselect('refresh');
});
} else { this.value = ''; }
});
});
How can I add a placeholder to a contenteditable div like allowed in a input or textarea field?
<textarea placeholder="Enter content here..."></textarea>
Javascript:
<script type="text/javascript">
function checkNoLabel(divId,type) {
if (type == "off") {
if (document.getElementById(divId).innerHTML == "" || document.getElementById(divId).innerHTML == "<br>") {
document.getElementById(divId).style.color = "silver";
document.getElementById(divId).innerHTML = "Enter content here...";
}
}
if (type == "on") {
if (document.getElementById(divId).innerHTML == "Enter content here...") {
document.getElementById(divId).innerHTML = "";
document.getElementById(divId).style.color = "black";
}
}
}
</script>
HTML:
<div contenteditable="true" id="theDivId" style="color:silver" onFocus="checkNoContent(this.id,'on')" onBlur="checkNoContent(this.id,'off')">Enter content here...</div>
This will put a placeholder on blur (on click/tab away) if the field is empty and will remove the placeholder on focus (click/tab).
I am using the accordion directive from http://angular-ui.github.com/bootstrap/ and I need to have two buttons in the header part.
Add - Create exactly same accordion below the original.
Remove - Remove the accordion. (the first accordion can not be removed -
disable the Remove button).
I am new to AngularJS and please help me to achieve this.
See a working plunker.
You just need a add and remove function in your controller
$scope.addGroup = function(idx, group, e) {
if (e) {
e.preventDefault();
e.stopPropagation();
}
var newGroup = angular.copy(group);
newGroup.no = $scope.groups.length + 1;
$scope.groups.splice(idx + 1, 0, newGroup);
};
$scope.removeGroup = function(idx, e) {
if (e) {
e.preventDefault();
e.stopPropagation();
}
$scope.groups.splice(idx, 1);
};
and a ng-repeat for your html:
<accordion close-others="oneAtATime">
<accordion-group heading="{{group.title}}" ng-repeat="group in groups">
<accordion-heading>
{{ group.title }} ({{group.no}})
<button class="btn btn-small" ng-click="addGroup($index, group, $event)">+</button>
<button class="btn btn-small" ng-click="removeGroup($index, $event)" ng-show="$index">-</button>
</accordion-heading>
{{group.content}}
</accordion-group>
</accordion>
put just this e.originalEvent.cancelBubble=true;
$scope.addGroup = function(idx, group, e) {
if (e) {
e.originalEvent.cancelBubble=true;
}
var newGroup = angular.copy(group);
newGroup.no = $scope.groups.length + 1;
$scope.groups.splice(idx + 1, 0, newGroup);
};
$scope.removeGroup = function(idx, e) {
if (e) {
e.originalEvent.cancelBubble=true;
}
$scope.groups.splice(idx, 1);
};
In my MVC application have included a button called form Field. whenever user clicks on that button dropdownlist gets displayed in modal box that contains text, checkbox etc as option.
function Select_type(box) {
var tp = document.getElementById('Type').value;
switch (tp) {
case "Text":
{
var editor = CKEDITOR.instances.message;
editor.insertHtml('<input type="text" id="tx" />');
}
break;
case "Checkbox":
{
var editor = CKEDITOR.instances.message;
editor.insertHtml(' <input type="checkbox" id="chk" name="chk" />');
}
break;
case "Radio":
{
var editor = CKEDITOR.instances.message;
editor.insertHtml('<input type="radio" id="rd" name="rd" />');
}
break;
case "DropDown":
{
var ediotr = CKEDITOR.instances.message;
ediotr.insertHtml('<select id="options"></select>');
dhtmlx.modalbox({
title: "Form Field Properties",
text: "<div id='form_in_box'><div ><label>Field Options:<input id='txt'></label><br></div><div><span class='dhtmlx_button'><input type='submit' value='Add' style='width: 86px' onclick='Add_type(this)'></span><span class='dhtmlx_button'><input type='button' value='Cancel' onclick='close_file(this)' style='width:80px;'></span></label></div></div>",
width: "300px"
});
}
break;
case "Listbox": alert("Listbox");
break;
}
dhtmlx.modalbox.hide(box);
}
When user selects drop down option a modal box appears that allows the user to add option to the drop down list
function Add_type(box) {
var txt = $('#txt').val();
if (txt.length > 0) {
$("#options").append("<option value='" + (txt.length - 1) + "'>" + txt + "</option>")
}
}
Textarea and button appears in modal box but it doesn't add the options that user has entered in textarea
function Add_type() {
var txt = $('#txt').val();
if (txt.length > 0) {
var lBox = $('select[id$=options]');
$(lBox ).append("<option value=' " + (txt.length - 1) + " '>" + txt + "</option>")
}
}
I tried like this, it was working
I want to detect when a user start type intp jquery mobile list view filter input.
Also get which buttons user type.
<ul data-role="listview" data-filter="true">
<li>Acura</li>
<li>Audi</li>
<li>BMW</li>
</ul>
Any help would appreciated.
Note : This is a PhoneGap app.
Found how to do it. Im posting it if anyone have same question.
$('div.ui-input-search').delegate("input", "keyup",
function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code != 8) {
//Any key other that backspace clicked
var text = $(this).val();
if (text.length == 1) {
//Just Started Typing
}
}
}
);
$('div.ui-input-search').delegate("input", "keydown",
function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 8) {
// BackSpace is clicked.
var remainingText = $(this).val();
if (remainingText.length == 1) {
//Cleared all characteres
}
}
// console.log(code+'\n\n\n');
// var remainingText = $(this).val();
// console.log(remainingText);
}
);