This is a migrated thread and some comments may be shown as answers.

How to Validate New Custom Entries.

4 Answers 179 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 19 Feb 2013, 04:02 PM
Hello,

I have the AllowCustomEntry set to true and I have the following scenario:
If the new Entry is an Email (has an email format) then add it normally, if the new Entry is not an email then
Check if the New Entry Exists in the DataSource/ENtryCollection, if it Exists then Do Nothing, if it doesn't exist
then I need to set the Background Color of the new Entry to Red.

This is what I have so far:


<script type="text/javascript">
    function OnClientEntryAdded(sender, eventArgs) {

        var newEntry = eventArgs.get_entry().get_text();
        if (validateEmail(newEntry)) {
             // If New Custom Entry is an Emeail Do Nothing
        }
        else {
// ELSE
// If New Custom Entry is Not an Email and It Does Not Exist in the 
// DataSource/Items then I want the New Added Entry to have a RED
// Background Color so that it indicates that the Entry is incorrect.
            
// IF newEntry does NOT exist in the EntryCollection THEN
// Change the Background COlor of the New ENtry to Red
        }
    }
 
 
    function validateEmail(email) {
 
        var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
             
        return re.test(email);
    }
</script>


I also need to know how to use the remove() entry function within that event.




4 Answers, 1 is accepted

Sort by
0
Eric
Top achievements
Rank 1
answered on 20 Feb 2013, 02:17 PM
Any help would be appreciated, thank you, I have looked at the client side programming functions but I still was unable to achieve what I wanted so I need your help.
0
Eric
Top achievements
Rank 1
answered on 21 Feb 2013, 02:07 PM
Should I submit this ti a support ticket? I haven't seen much help for this control in the documentation, 
0
Nencho
Telerik team
answered on 22 Feb 2013, 03:37 PM
Hello Eric,

The datasource, which the RadAutoCompleteBox  is populated with, is not accessible at client-side.This is because the datasource is based on the typed in the input text. Each time a character is typed, a new request to the database is initiated, in order to retrieve the corresponding data. Therefor, I can suggest you to verify the entered token and check if it is present in the datasource at server-side. You could use the OnEntryAdded and assign a value to the entry, which did not met the validation. In addition, at OnClientLoad you could loop through all entries set the background color for those with the above mentioned value. Please consider the following implementation:

protected void RadAutoCompleteBox_EntryAdded(object sender, AutoCompleteEntryEventArgs e)
  {
      //perfomr validation here.
      e.Entry.Value = "notValid";
  }

OnClientLoad:
<script type="text/javascript">
 
     function onClientLoad(sender) {
         var entries = sender.get_entries();
         var entriesCount = entries.get_count()
 
         for (var i = 0; i < entriesCount; i++) {
             var entry = entries.getEntry(i);
             if (entry.get_value() == "notValid") {
 
                 entry.get_token().style.backgroundColor = "Red"
             }
         }
 
     
 </script>

style
<style type="text/css">
        html .RadAutoCompleteBox_Default .racToken {
            background-image: none;
        }
    </style>




Kind regards,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Eric
Top achievements
Rank 1
answered on 22 Feb 2013, 09:29 PM
Hello Nencho
Thanks for the hlep and the suggestions
If I add the "RadAutoCompleteBox_EntryAdded" event to RadAutoComplete that would
cause a postback each time an entry
is added which is not a desired behavior, I don't want to access the Data Source per se 
In code behind I access the Entries collection like so:

AutoCompleteBoxEntryCollection bccEntryCollection = MailBCCAutoComplete.Entries;


I want to access the Entries collection from client.

If that also isn't possible the only thing that comes to mind is using jQuery Ajax, get the
DataSource from there and then make the comparison client side.

Tags
AutoCompleteBox
Asked by
Eric
Top achievements
Rank 1
Answers by
Eric
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or