Possible to add new item to autocomplete item list?

5 posts, 0 answers
  1. Anurag
    Anurag avatar
    27 posts
    Member since:
    Apr 2016

    Posted 01 Oct Link to this post

    Hi

    I wanted to check if the user types out an item that is NOT present in the items array then is it possible to push what the user has typed as a new item into the array and select the same.

    Thanks

  2. Nikolay Iliev
    Admin
    Nikolay Iliev avatar
    295 posts

    Posted 02 Oct Link to this post

    Hello Anurag,

    The RadAutocomplete control does not provide this functionality out-of-the-box.
    However, you can access the native controls behind he RadAutocomplete and create your event handles (e.g., for textChange in Android) and implement your logic on what to happen when the user enters a non-existing token value.

    For example:
    var autocmp = args.object; // get reference to your RadAutoCompleteTextView either via loaded or via getViewById
      
    console.log("autocmp: " + autocmp) // RadAutoCompleteTextView
      
    var nativeTField = autocmp.android.getTextField();
    console.log("nativeTextField: " + nativeTField) // android.widget.EditText (the Android native widget EditText)
      
    nativeTField.addTextChangedListener(new android.text.TextWatcher({
      
        afterTextChanged(s) {
            console.log("afterTextChanged");
            console.log(s);
        },
        beforeTextChanged(s, start, count, after) {
            console.log("beforeTextChanged");
            console.log(s);
            console.log(start);
            console.log(count);
            console.log(after);
        },
        onTextChanged(s, start, before, count) {
            console.log("onTextChanged");
            console.log(s);
            console.log(start);
            console.log(before);
            console.log(count);
        }
    }));

    Based on that approach you can now check how the user input has changed and introduce your new tokens on the fly.

    Regards,
    Nikolay Iliev
    Progress Telerik
    Did you know that you can open private support tickets which are reviewed and answered within 24h by the same team who built the components? This is available in our UI for NativeScript Pro + Support offering.
  3. Anurag
    Anurag avatar
    27 posts
    Member since:
    Apr 2016

    Posted 02 Oct in reply to Nikolay Iliev Link to this post

    Hi Nikolay

    Thanks for the suggestion, it helps. Since I need a similar functionality on IOS as well, is there some way to achieve a similar outcome on IOS too. 

    Best,

    Anurag

  4. Nikolay Iliev
    Admin
    Nikolay Iliev avatar
    295 posts

    Posted 02 Oct Link to this post

    Hello Anurag,

    Accessing the events responsible for text change in UITextField (which is the extended native control behind the textField property in RadAutomcompleteTextView is a not a straightforward task, and we would not recommend it as it might change the way the control works. Currently, the only officially supported events for iOS are the one posted here.

    However, if you want to experiment and provide custom logic, you can do that with overwriting the delegate method responsible for providing the methods for user interaction.

    For example:
    let radAutomComplete = <RadAutoCompleteTextView>args.object;
     
    let tkAutoComplete = radAutomComplete.ios // TKAutoCompleteTextView http://docs.telerik.com/devtools/ios/api/Classes/TKAutoCompleteTextView.html
     
    tkAutoComplete.delegate // overwrite the delegate method http://docs.telerik.com/devtools/ios/api/Classes/TKAutoCompleteTextView.html#//api/name/delegate

    Example on how to overwrite a delegate method using TypeScript can be found here.

    Once again this is not recommended approach as it could break your application if and when internal changes are made to RadAutocompleteTextView.



    Regards,
    Nikolay Iliev
    Progress Telerik
    Did you know that you can open private support tickets which are reviewed and answered within 24h by the same team who built the components? This is available in our UI for NativeScript Pro + Support offering.
  5. Anurag
    Anurag avatar
    27 posts
    Member since:
    Apr 2016

    Posted 02 Oct in reply to Nikolay Iliev Link to this post

    Hi Nikolay

    Thanks for your prompt response and your advice. In that case,  I will avoid this approach and explore providing a different interface to add new text data to the items array.  I have put in a feature request here to provide a way to easily access the text entered into the autocomplete view.

    Regards

    Anurag

     

Back to Top