EasyUI Forum
September 14, 2025, 07:03:37 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Poll
Question: searchbox: is it possible to set the message if search failed (like validatebox msg)?
Good question - 0 (0%)
Not interested - 0 (0%)
Total Voters: 0

Pages: [1]
  Print  
Author Topic: searchbox: setting message if not found.  (Read 7412 times)
vladj
Newbie
*
Posts: 5


View Profile
« on: December 19, 2018, 08:45:18 AM »

Hi!

I am using searchbox like this:

Code:
<input id="search" style="width:200px;">

and

Code:
	$('#search').searchbox({
     searcher: doSearch,
   prompt: 'Enter search string'
});

In case doSearch() is unsuccessful I'd like to set the error message on the searchbox  similar to



but - of course - with different text, like "not found".

Is it possible? If so - how?

Thanks in advance!
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #1 on: December 19, 2018, 05:38:03 PM »

The searchbox component extends from validatebox, all the validating rules can be applied on this component.
Code:
$('#sb').searchbox({
required: true
})
Logged
vladj
Newbie
*
Posts: 5


View Profile
« Reply #2 on: December 20, 2018, 10:13:27 AM »

Sorry Jarry, but it does not answer my question.

My question is not how to make the search field required, but rather how to show the "tooltip"  similar to the "This field is required", BUT with:

  • custom text
  • later, after the return from asynchronous doSearch() function specified by "searcher:".

There seems to be no obvious way of doing it.

Your help is greatly appreciated!
 
Logged
jarry
Administrator
Hero Member
*****
Posts: 2298


View Profile Email
« Reply #3 on: December 21, 2018, 03:32:27 AM »

To display the tooltip, create it on the box.
Code:
$('#sb').searchbox('textbox').tooltip({
content: 'msg'
})
Call the 'update' method to update the tooltip content.
Code:
$('#sb').searchbox('textbox').tooltip('update', 'new msg')
Logged
vladj
Newbie
*
Posts: 5


View Profile
« Reply #4 on: January 14, 2019, 09:00:12 AM »

I finally managed to implement it in the same look an feel as the original error message tooltip. Here it is:

Code:
$.extend($.fn.searchbox.methods, {
showError: function(jq, text) {
return jq.each(function() {
                var textbox = $(this).searchbox('textbox');
textbox
        .addClass('textbox-invalid')
.tooltip({
content: text,
position: "right",
deltaX: 24
})
.tooltip('show')
.tooltip('tip').css({
color: "#000",
borderColor: "#CC9933",
backgroundColor: "#FFFFCC"
});
});
}
});

And to call it just use

Code:
	$('#search').searchbox('showError','Not found');       

Where the searchbox is defined with the 'search' ID:

Code:
<input id="search" class="easyui-searchbox" style="width:300px"
data-options="prompt:'Please Input Value'">
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!