I would like display some Html.DropDownList controls in custom readonly mode.
Control should be able to open underlaying popup but it shouldn't save values that selected by user.
For example I have Html.DropDownList control with three values:
Value 1
Value 2
Value 3
Selected item for control "Value 2"
User see combobox control with displayed item "Value 2".
When user click on control popup with all three values should be opened (as for usual combobox control). In case user choose value different from "Value 2" selected value shouldn't be saved in control. So, when user click on item "Value 3" from underlying list, control should still display item "Value 2" as selected
Is it possible in any way?
Thank you
Ugh. As a user of your system, I will not like what you have created here! The first time I try to click on Value 3, and it pops back to Value 2 without any warning, I will assume that I mis-clicked, and I will immediately try again. Hopefully I will realize that you are re-setting that dropdown list, but I won't get it right away, and I'll be annoyed.
Here's a better UI choice: Disable the invalid OPTION tags so that I can see them in the dropdown, but I can't select them. Here's the jQuery for it:
$(function () {
$("#select[name=test] option").not(":selected").attr("disabled", true);
});
I learned from an experienced programmer (not even a 'real' design guy), that the biggest sin of UI design is allowing the user to select an invalid option. Do everything in your power to avoid have to 'correct' what the user picked. By allowing them to select an invalid option, and then un-doing it instantly with JavaScript without any user feedback, you are violating this guideline.
If you are ok. with using jQuery. This should work for you.
(function () {
var previous;
// Grab the initial value in focus event.
$("select[name=test]").focus(function () {
previous = this.value;
// On change event, use previous to set the value of dropdown.
}).change(function() {
$("select[name=test]").val(previous);
});
})();
Here is the working example.
Inspired by another StackOverflow answer.
Related
I have an AppMaker app that has a from based off of one address table/datasource. I can get a form with next/prev buttons, but replaced the key field (name) with a dropdown list of all names (a user can start typing names to jump there, with the dropdown showing).
My hope is that when a user selects from the dropdown, the entire form updates and the next/prev buttons work properly as well (there too many records to page thru with next/prev only). I don't have to have next/prev functionality if it complicates things too much.
Currently the dropdown is working, but I cannot get the index for the next/prev buttons set or the rest of the form to reflect the selected dropdown record.
I've tried to set the "onValueEdit" event to something like this...
var selected = widget.value;
var idx = widget.options.indexOf(selected);
console.log("Selected: "+selected+", index = "+idx+"\n");
if(idx < 0) { //...this error is never hit
console.log("Index error - setting to zero!\n");
idx = 0;
}
widget.datasource.loadPage(idx); //...update form?
Two observations via console logging:
The "idx" var is never set to the selected dropdown index reliably, and is
often "0" (tho no error msg ever shows), so the "indexOf()" function
isn't working as expected.
The "selected" var (name) is always correct.
If I call widget.datasource.loadPage(...) with a fixed value (say 5) it has no effect on what is shows in the form either (previous loaded data remains) - obviously not the way to do it :v/
Can you steer a noob in the right direction?
If you are using default App Maker form, then you can see that so-called pager, doesn't actually paginate. It triggers prevItem/nextItem datasource methods, in other words it navigates through datasource items, not pages. Here is a quote from App Maker docs:
nextItem: Selects the next item. For Query Datasources, if the current item is the last item on the page, then this loads the next page and selects the first item on the newly loaded page.
So, if you already have all your items loaded(you set query page size for your datasource to 0), then you need just to change selected item within datasource:
// onValueEdit dropdown event
// assuming, that form and dropdown share same datasource
widget.datasource.selectKey(newValue._key);
If you really have lots of items and it is not feasible to load all of them in one call... then it will be all another story...
UPDATE:
It's important that Options and Value are set as shown in the image below!
However, I had trouble setting them that way (read: wasted hours!) until I wiped them both completely using More options in the binding picklist, and tried again (I had even tried on a brand new app!). I was being forced to choose ..projections.. and then a final field before the OK button would be available.
Not sure if AppMaker is buggy here or there is something simple I'm not understanding!
None of the coding in my original question is required.
Once set this way, binding just works as you would expect it!!
All other fields are set as #datasource.item. and are bound to whatever item is chosen. No Events settings are necessary for the dropdown either, as I thought they might be.
I deleted this page and started again, and replaced the default business name data field with a drop down, I set the dropdown as:
Options: #datasources.Addresses.items
Value: #datasources.Addresses.item
It works fine?! Not sure what happend in my original page!
UPDATE:
So it seems you need to delete both the Value and Options and then re-enter these. The OK will light up when you do.
Also, my original take on App Maker was to build the UI and attach data. That was my first mistake. You build the data then have App Maker build edit/add pages for you.
I have almost every piece of code, I just need it to be optimized using correct IF_ELSE conditions and arranging the right flow.
I have a webform (UserProfile.aspx), which contains FormView (to display user profile).
In FormView ItemTemplate, I have put simple HTML and ASP.Net Labels to display Info using Label's Text property :
Eval("col_name");
In EditItemTemplate, I have same table with but textboxes instead of Labels.
I have a button "Edit", on its Click event, I'm changing FormViewMode
FormView1.changeMode(FormViewMode.Edit); [ WORKING ]
I have another button "Cancel", on its Click event, I'm changing FormViewMode
FormView1.changeMode(FormViewMode.ReadOnly); [ <-- NOT WORKING ]
To display user profile, I'm passing user-id from querystring (querystring field = "user")
So the valid URL looks like :
/UserProfile.aspx?user=121
What I want to achieve is :
If (user_IS_Logged_In)
//Some basic tasks like setting welcome message label with username/email etc.
If (querystring_is_EMPTY OR querystring_field_is_incorrect OR user_IS_NOT_Logged_IN)
//Remove the Edit and Cancel buttons
If (querystring_field_is_exist)
//initialize user_id (this will be passed to ShowUserDetails(user_id))
If (user_IS_Logged_In AND querystring_is_exist)
If querystring value and logged in user_id ARE NOT EQUAL THEN
//Again Remove the Edit and Cancel buttons
P.S --> I'm thinking to add an UpdatePanel around the FormView Once I achieve above tasks, for consistent look.
I know the problem is quite difficult to understand so feel free to ask details.
I will provide the code as needed.
I have created a site that allows users to see a list of files that currently reside on my FTP site.
I have got the files appearing but when I select one and click download, it is not registering that I have selected an item.
At the moment I am using:
If CheckBoxList1.SelectedItem.Value = "" Then
MsgBox("A file needs to be selected...!")
End If
'NOTE - A SELECTION ISN'T BEING RECORDED BY THE PROGRAM!!'
If CheckBoxList1.SelectedItem.Value <> "" Then
I think that it is not registering the selection being made, because the item being selected is not a string value.
But I am not sure what to set this as.
It would help if you provided the actual code being used to attach the selection / change handler as well as the event method body.
I'm guessing your attaching to the checkbox SelectedIndexChanged event. If that's the case then make sure that you have actually bound a "value" to the checkbox list, ensure that you are using the "DataTextField"and "DataValueField" properties instead of just default binding the checkboxlist to a collection.
I am using the AutoCompleteExtender on a commercial site. My problem is the users are quickly typing in part of a word and immediately pressing "Enter" which causes the AutoComplete control to NOT come back with a list of suggestions. For example, if my database has the phrase "Texas, United States" in it but the users just type "Texas" quickly followed by Enter then the dropdown list does not appear.
What I would like is for the AutoComplete control to ignore the fact the user has pressed Enter and go and fetch the suggested data anyway. (The ultimate would be if it ignored Enter when there was currently no list, but selected an item when there was a list).
I can simulate this exact problem by going to the samples section of this Microsoft ASP.NET site and typing in some characters very quickly followed by 'Enter'.
Please could someone tell me what I need to do?
Thanks, Martin
I've hacked around this problem before with an extra keydown handler on the textbox that is the target of the auto-complete. Replace this._autoCompleteBehavior in the snippet below with a reference to your instance of AutoCompleteBehavior (obtainable via $find() and the BehaviorID). The idea here is to force the auto-complete behavior to think it needs to perform a lookup by calling _onTimerTick(), which executes after the typing delay has expired. By default the typing delay gets cancelled by hitting the enter key, so this just forces the lookup anyway on enter or tab.
Disclaimer: my hack references "private" members of the AjaxControlToolkit code (stuff that starts with underscore is "private"), so it is probably not guaranteed to be future-proof.
_searchTextbox_keydown: function(e)
{
var key = e.keyCode || e.rawEvent.keyCode;
// If the user hits enter or tab before the auto complete popup appears, force the autocomplete lookup at that moment.
if ((key === Sys.UI.Key.enter || key === Sys.UI.Key.tab) && this._autoCompleteBehavior._currentPrefix != this._autoCompleteBehavior._currentCompletionWord())
{
this._autoCompleteBehavior._onTimerTick(this._autoCompleteBehavior._timer, Sys.EventArgs.Empty);
e.preventDefault();
}
}
Hey try jQuery or YUI autocomplete extender. It will be lightning fast.
I'm developing an ASP.NET form for data-entry. Users have to select a client from a dropdownlist that is filled with about 1000 clients.
Now the client list is growing and the users have requested that I add a lookup feature: they'd like to type part of the name and filter the dropdownlist with clients whose name match. So if they type 'aaa' they'd like to see only clients with 'aaa' somewhere in their name.
I have looked at the ajax control toolkit's AutoComplete but that works on textboxes, not dropdownlists.
Can anyone suggest a nice solution?
Use it on a textbox then! Surely the person looking in the dropdown list knows the name of the client. There is little difference, in my opinion, in this scenario.
I have been using a jQuery tag suggest add in on my MVC app which works very well.
http://remysharp.com/2007/12/28/jquery-tag-suggestion/
If you are interested just comment and i will give you the code i am using.
If you really want to use a dropdown list you could have a textbox and dropdown list in an update panel. When the users enters the text (and clicks a button) you could then populate the dropdown using results filtered to what the users types.
I think a textbox would actually be preferred for this. A select box doesn't invite typing - so it becomes a bit of a hidden trick to filter it (not to mention that Firefox will pretty much do it right anyway).
You can easily throw an image next to a textbox to indicate that it has options, which allows both mouse driven or keyboard driven interaction.
I'm partial to JQuery, so I'd use JQuery's autocomplete - which has config options to require a match, or that clicking the box will drop down all items.
If you're interested in "progressive enhancement", you may be best off with both a traditional select input (for accessibility) that gets replaced by an autocomplete textbox driven off the same data. Something like:
<select id="s">
<option value="foo">Foo</value>
<option value="bar">Bar</value>
</select>
var d = $('#s OPTION').map(function() {
return $(this).text();
});
$('#s').hide().append('<input type="text" />')
.autocomplete(d, {
mustMatch: true,
minChars: 0,
autoFill: true,
matchContains: false
})
.result(function(e, d, f) {
// Select option for the form to submit
$('#s').val(d);
});
You could also leave the select visible - which makes it more flexible, but potentially more confusing - and hook an event handler to the select box to update the textbox as well so that they stay in sync.