During a form compilation i need to be able to insert a value, presenting a list of already used values (usual listbox behavior).
But i also need to be able to enter a new value, so i choosed aui:autocomplete (code below).
By default it allows selection of multiple items separated by the "delimChar" separator.
Is there any way to limit to 1 single value selection (or new value)?
var catArray = new Array();
<%for (String s : categoryList) {%>
catArray.push('<%=s%>');
<%} %>
var autoCompleteCategory = new A.AutoComplete(
{
contentBox: '#<portlet:namespace />contactOptions',
input:'#<portlet:namespace/>category',
dataSource: catArray,
delimChar: ',',
typeAhead: true,
}).render();
Making comment as the answer for better visibility:
You can remove the attribute delimchar: ',' from the following code:
var catArray = new Array();
<%for (String s : categoryList) {%>
catArray.push('<%=s%>');
<%} %>
var autoCompleteCategory = new A.AutoComplete(
{
contentBox: '#<portlet:namespace />contactOptions',
input:'#<portlet:namespace/>category',
dataSource: catArray,
delimChar: ',', // **remove this attribute**
typeAhead: true,
}).render();
I think this should work.
Also clear your browser cache before trying it :)
Related
If I have a form in extjs I can get the data using this
var values = form.getValues();
Unfortunately this only returns fields which are enabled. I also have fields which are disabled. For example I have an ID field which is disabled, because obviously you do not want to modify the ID. So the getValues() method is pretty useless IMO.
There is also getRecord().data which gives me all the values in the form.
form.getRecord().data
Great! But all the data is out of data, and it doesn't reflect modifications done in the form.
I looked at getFieldValues() too, but again this only gives me values of fields that are enabled.
Is there any method out there that will give me exactly all the data in the form as is on the screen? or do I have to write a huge hack to give myself this functionality?
Set the fields to readOnly instead of disabled.
Or do this with a component Query:
var form = formpnl.getForm();
var disableditems = formpnl.query('[disabled=true]');
Ext.each(disableditems, function(item) { item.enable(); });
var values = form.getValues();
Ext.each(disableditems, function(item) { item.disable(); });
console.log(values);
If you want to simulate disabled fields, you can have the following CSS class:
.textFieldDisabled .x-form-text {
background-color: #B1B2B4;
background-image: none;
}
And have this in your view markup:
{
xtype: 'textfield',
fieldLabel: 'User ID',
name: 'UserID',
readOnly: true,
cls: 'textFieldDisabled '
}
getValues() will return the value for this field and it'll look disabled to the user.
Not sure if this is possible but I'm trying, and keep coming up short.
http://plnkr.co/edit/Gcvm0X?p=info
I want a 'E' (element) directive that is replaced with a more complex nested HTML node using the 'templateUrl' feature of directives.
HTML defining the directive (form tag included for complete mental image):
<form id="frm" name="frm">
<ds-frm-input-container
class="col-md-1"
frm-Name="frm"
frm-obj="frm"
input-name="txtFName"
ds-model="user.firstName"></ds-frm-input-container>
</form>
TemplateUrl contents which 'replaces' the above directive 'ds-frm-input-container' HTML element:
<div>
<input
required
ng-minlength=0
ng-maxlength=50
class="form-control"
ng-model="dsModel"
placeholder="{{dsPlaceHolder}}" />
<span ng-if="showErrs" class="label label-danger">FFFFF: {{dsModel}}</span>
</div>
Controller and Directive:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = "Nacho";
$scope.user = {};
$scope.user.firstName = "";
})
.directive('dsFrmInputContainer', function(){
var ddo = {
priority: 0,
restrict: 'AE',
scope:
{
frmName: '#',
inputName: '#',
dsPlaceHolder: '#',
dsModel: '=',
frmObj: '='
},
templateUrl: 'template1.html',
replace: true,
controller: function($scope)
{
$scope.showErrs = true;
},
compile: function compile(ele, attr) {
return {
pre: function preLink(scope, ele, attr, controller)
{
},
post: function postLink(scope, ele, attr, controller)
{
var txt = ele.find('input');
txt.attr('id', scope.inputName);
txt.attr('name', scope.inputName);
//BLUR
txt.bind('blur', function () {
console.log("BLUR BLUR BLUR");
angular.forEach(scope.frmObj.$error, function(value, key){
var type = scope.frmObj.$error[key];
for(var x=0; x < type.length; x++){
console.log(type[x]);
}
});
event.stopPropagation();
event.preventDefault();
});
}
};
},
};
return ddo;
});
The directive replaces just fine and the input element is named just fine. The form object however doesn't include the input element name in the error information. This makes it impossible for me to single out the input element during a 'blur' event that is setup in the directive.
I am doing this trying to reduce the show/hide logic 'noise' in the html for error messages (spans) and it should be reusable.
UPDATE (2014.01.28):
2014.01.28:
Added promises. There is a service that allows validation on button clicks. NOT USING built in angular validation anymore found some compatibility issues with another library (or viceversa).
ORIGINAL:
Here is my form validation directive vision completed (plnkr link below). Completed in concert with the help of the stack overflow community. It may not be perfect but neither are butterfingers but they taste good.
http://plnkr.co/edit/bek8WR?p=info
So here is a link that has the name variables set as expected on the given input form error object. http://plnkr.co/edit/MruulPncY8Nja1BUfohp?p=preview
The only difference is that the inputName is read from the attrs object and is not part of the scope. This is then read before the link function is returned, in the compile phase, to set the template DOM correctly.
I have just spent quite a while trying to sort this problem out, and while this is not exactly what you were looking for, his is my attempt. It uses bootstrap for all the styling, and allows for required and blur validation, but its definitely not finished yet. Any thoughts or advice much appreciated.
https://github.com/mylescc/angular-super-input
So right now I have a partial view that just has a list of possible actions, here is the main portion:
<%= Html.ActionLink("Show", "Show", new { id = dbId, css="/Content/Site.css" }) %> |
<%= Html.ActionLink("Edit", "Edit", new { id = dbId }) %> |
<%= Html.ActionLink("Delete", "Delete", new { id = dbId }, new { #class = "deleteLink" })%>|
<%= Html.ActionLink("Print", "Show", new { id = dbId, css="/Content/Other.css"}) %>
Essentially, there is a Show and and Print option, I decided it would be more convenient to not create a new view for print, and just overload the Show Action by passing an extra parameter that would tell which CSS to display, and then use ViewData to set the CSS for the view.
Is this good practice?
Should I create a new view? They are completely the same except for the CSS.
If the css is the only thing that is different, you could just include the css and set the media type to be picked up when the user prints from the browser, e.g.:
<style media="print" ...
I am using following code to generate a list box..
<%: Html.ListBoxFor(m => m.Subscribers, new List<SelectListItem>(), new { #class = "list_style_Wizard" })%>
But we can select more than one items from the listbox.. How can i restric it to single select ???
The HTML helpers DropDownListFor and ListBoxFor seem to add the multiple attribute when rendering as a listbox. I use a combination of the DropDownListFor/ListBoxFor and a jQuery livequery selector to remove the multiple attribute. In Razor use:
#Html.DropDownListFor(m => m.SelectedId, Model.SelectList,
new { size = 10, #class = "selectOneListBox" })
and in JavaScript:
$(".selectOneListBox").livequery(function () {
$(this).removeAttr('multiple');
});
I'm sure you could also write your own version of the HTML helper routine that doesn't spit out the multiple attribute.
Html.ListBoxFor is used to render a multiple choice list box. For single choice use
Html.DropDownListFor
<%: Html.DropDownListFor(m => m.Subscribers, listOfsubscribers, new { #class = "list_style_Wizard" }) %>
I've got a dropdownlist:
<%= Html.DropDownList("ddlNames", new SelectList(Model.NameList, "ID", "Name"))%>
I've got an ActionLink:
<%: Html.ActionLink("edit", "Edit", "Members", new { area = "MembersArea", id = XXX }, null)%>
I want the value of the dropdownlist in the XXX.
So I want to use values from controls on a view in the ActionLink.
Is that possible in a simple manner?
thanks,
Filip
You can't do this because the html helpers execute at the server side while the dropdown value can change at the client side. The only way to achieve it is to use javascript. You could register for the onchange event of the dropdown and modify the value of the href of the anchor:
$(function() {
$('#ddlNames').change(function() {
var value = this.value; // get the selected value
// TODO: modify the value of the anchor
});
});
This is probably not the best solution because the routes are configured on the server side and in order to modify the value of the link you need to do some string manipulation on the client side.
As an alternative you could use a form and a submit button instead of an anchor. This way the selected value of the dropdown will be automatically sent to the server and you don't need any javascript:
<% using (Html.BeginForm("Edit", "Members", new { area = "MembersArea" })) { %>
<%= Html.DropDownListFor(x => x.SelectedName,
new SelectList(Model.NameList, "ID", "Name"))%>
<input type="submit" value="Edit" />
<% } %>
Instead of modifying the value of the anchor every time a relevant dropdown is changed, just modify it once, on click.
Example using Razor:
#Html.DropDownList("DropDownFirstNames", new SelectList(Model.FirstNames, "ID", "Name"))
#Html.DropDownList("DropDownLastNames", new SelectList(Model.LastNames, "ID", "Name"))
#Html.ActionLink("Submit name", "ActionName", "ControllerName", null, new { #id = "SubmitName" })
<script type="text/javascript">
$('#SubmitName').click(function () {
var first = $('#DropDownFirstNames').val();
var last = $('#DropDownLastNames').val();
var path = '#Url.Content("~/ControllerName/ActionName")' + "?firstId=" + first + "+&lastId=" + last
$(this).attr("href", path);
});
</script>