A flitered drop down list from a text box.
This is an abstract class used by all implemented filter field types
The type of list this autocompleter returns. Posts ResultType. This is a defined enum created in the client application by overloading AutoCompleteBase.ResultType
The API endpoint that is called to retrieve all autocompleter operations.
Javascript function called to download a file.
The width of the rendered control. If -1 then is left empty for CSS to control.
Adds an inline style of "width: 100%" to the rendered control.
Make the control read only.
*** Makes the control disabled.
Set the focus to this control.
A list of extra Name Value string parameters to be posted along with the control. Allows extra IDs to be sent through.
Causes the Javascript validate event to fire on the control after loading to validate any entry in the control.
Allow the control to post back an entry even if it didn't match a valid item in the list. Useful for allowing additions to the list.
*** Any value entered into this control cannot already exist in the list of values. Posts unique=1 & valueid=value
Show an edit icon next to the AutoCompleter to navigate to another page to edit the value and other details.
If showEdit is true then the action to navigate to for the editing.
If showEdit is true then the action to navigate to for the editing.
This simulates the Save button being pressed to allow backend attributes to find the correct method to call.
Puts an icon next to the AutoCompleter to show a drop down list of all possible entries.
Show an add icon next to the AutoCompleter. This button needs javascript binding to do anything.
Adds a "Wide" class to the AutoCompleter textbox for use in certain situations.
*** The text to display on any edit button.
Posts through the value of a linked field for filtering the list displayed in this control.
With joined controls, both have to be valid for both to display as valid. Passes a Join=1 & Field=value
The control will not save values but instead always mirror the text. This allow a look up list but still act as a wildcard text field.
Adds "Active" to the Extra Parameters. When validating an initial value that has been loaded, this will get overridden to False to show any old matches that are no longer available to select. This prevents data deletion of historical records. If you want to enforce a match then use the hide-inactive-value-text attribute.
If the pre-existing value is inactive then do not show the related text regardless of any filter-active value. Used to override a filter-active to hide deleted entries and so force a correction on saving.
The posted parameter name to use.
The posted value.
This takes the value of ControlId and posts it as an Extra Paramater with a key of ParameterName along with its value.
The posted parameter name to use.
The id of the control to use to filter against.
Is the control being used to filter also an AutoCompleter control.
This control posts with every keypress to return a list of possible options.
A string representation of the enum for the type of list returned. This is a defined enum created in the client application by overloading AutoCompleteBase.ResultType
The search text to find.
Any extra parameters passed through to the backend API.
Guid of user making the call.
The returned data set
The list of matching results
Does the returned results include the Info field. This causes the list to display the extra Info line under each result.
The text value of the result.
The string value of the result.
The string value for the info display line.
Fires when a valid entry is found in the autocompleter field. Returns the valid value.
$('#MyFieldId').on('Valid', function (e, value) { } );
Fires when a valid entry is found in the autocompleter field. Returns the valid value and the previous value.
$('#MyFieldId').on('Valid', function (e, value, oldValue) { } );
Fires when a valid entry is not found in the autocompleter field. Returns the invalid value.
$('#MyFieldId').on('Invalid', function (e, value) { } );
Clears the AutoCompleter field and prevents the result list from displaying. This can be used when another field is not valid and you wish to prevent entries into this field.
ShareItLibrary.AutoCompleter.Clear('MyFieldId');
Initialises the Autocompleter field. Used for dynamic loading to bind events after page has loaded.
ShareItLibrary.AutoCompleter.InitSingle('MyFieldId');
After setting a value via javascript into an autocompleter field value, refresh the text to show the result.
ShareItLibrary.AutoCompleter.AutoCompleteValueText('MyFieldId');
Sets the value on the field $('#MyAutoCompleter').setvalue('123', 'Hello');
Clears value and text on the field $('#MyAutoCompleter').SiAcClear();
Helper functions.
public static IActionResult EditAction(Func<IActionResult> defaultAction, HttpContext context, ITempDataDictionary tempData)
Used on the Save method of a controller if Edit button is used. If Save is ok then call return AutoCompleterHelper.EditAction(() => EditBack(), HttpContext, TempData);
public class AutoComplete : AutoCompleteBase{ public new enum ResultType { MyType } public override AutoCompleteResults FindResults(AutoCompleterQuery acq) { return (ParseResultType()) switch { ResultType.MyType => MyType(acq), _ => new AutoCompleteResults(new List()) }; } public override AutoCompleteBase.ValidateValueResult ValidateValue(AutoCompleterValidate acv) { return (ParseResultType()) switch { ResultType.MyType => ValidateMyType(acv), _ => new ValidateValueResult() }; } private AutoCompleteResults MyType(AutoCompleterQuery acq) { List items = new(); var qs = (IQueryable)db.MyModel; if (!acq.FullList) qs = qs.Where(e => e.MyType.Contains(Search)); if (Active != null) qs = qs.Where(e => e.Active == Active); var customId = Field("CustomId"); // Only add this line if needed. if (customId != null) // Only add this line if needed. qs = qs.Where(e => e.CustomId == customId); // Only add this line if needed. qs = qs.Include(e => e.IncludedEntity).OrderBy(e => e.MyType).Take(acq.FullList ? fullListCount : listCount); foreach (var q in qs); { Result r = new(); { Text = myType.Text, Value = myType.ValueId.ToString(), Info = myType.Description // Only add this line if needed. }; items.Add(r); } return new AutoCompleteResults(items, true); } private ValidateValueResult ValidateAccelerator(AutoCompleterValidate acv) { ValidateValueResult vvr = new(); try { Guid id = new Guid(acv.Value); var q = db.MyModel.Find(id); if (q != null) { vvr.Text = myType.Text; vvr.Value = value; vvr.IsValid = true; } } catch { } return vvr; }}<autocompleter asp-for="MyFieldId" type="AutoComplete.ResultType.MyType" extra-parameters="@new EpsActive()"></autocompleter><autocompleter asp-for="MyFieldId" type="AutoComplete.ResultType.MyType" class="form-control" extra-parameters="@new EpsActive()" filters="@(new List<AutoCompleterFilter> { new AutoCompleterFilter("CustomId", "MyControlId") })"></autocompleter>;