In my rails + angular
application, I am utilizing semantic ui
. There is a search dropdown that displays undefined values when typing the letter s
, but works fine for other single letters. Strangely, no server request is made when typing the letter s
, and I'm struggling to understand why this is happening. Below is the code snippet, any help would be appreciated.
Here is the JavaScript code:
$('.ui.product.search').dropdown({
fullTextSearch: true,
preserveHTML: false,
debug: true,
saveRemoteData: false,
sortSelect: true,
match: 'text',
regExp: {
escape: /[-[\]{}()*+?.,\\^$|#\s]/g,
},
apiSettings: {
url: '/gpr/v1/product_codes/search?name={query}',
},
});
And here is the Rails controller action:
def search
# byebug
search_query = ""
if not params[:name].blank?
search_query = "%#{params[:name]}%"
end
@product_codes = ProductCode.where("H3Description LIKE ?", search_query)
#render json: {results: @product_codes }
end
Lastly, the HTML code:
<div class="two fields">
<div class="field">
<label><%= t 'asset.create.h3' %></label>
<select name="products" class="ui product search dropdown" ng-model="asset_details[0].type_details[$index].crop">
</select>
</div>