Serenity: LookupEditor case insensitive - Value

Created on 15 Jun 2018  路  2Comments  路  Source: serenity-is/Serenity

How to make the LookupEditor case insensitive, the DB has values that are like so "un" and "UN" and I want to both be binding because the database is case insensitive.

Any suggestions ?

community-support question

Most helpful comment

You can try to make a Lookup editor and override query option of select2Options...

For example

namespace YourNamespace {
    @Serenity.Decorators.registerEditor()
    export class ExtLookup extends Serenity.LookupEditorBase<ExtLookupOptions, any> {

        constructor(container: JQuery, opt?: ExtLookupOptions) {
                    super(container, opt);
        }

        public getSelect2Options() {
            var selec2Options = super.getSelect2Options();

            selec2Options.query = this.queryCustom;
        }

        protected queryCustom(p1: Select2QueryOptions) {
                var term = (Q.isEmptyOrNull(p1.term) ? '' : Select2.util.stripDiacritics(Q.coalesce(p1.term, '')).toUpperCase());

          var results = (this as any).data.filter((item) => {
                  [ADD YOUR LOGIC HERE]
          }

             var res: Select2Result = {
                results: results.slice((p1.page - 1) * 100 /*this.pageSize*/, p1.page * 100/*this.pageSize*/),
                more: results.length >= p1.page * 100/*this.pageSize*/,
                context: p1.context
            }
            p1.callback(res);
        }

All 2 comments

You can try to make a Lookup editor and override query option of select2Options...

For example

namespace YourNamespace {
    @Serenity.Decorators.registerEditor()
    export class ExtLookup extends Serenity.LookupEditorBase<ExtLookupOptions, any> {

        constructor(container: JQuery, opt?: ExtLookupOptions) {
                    super(container, opt);
        }

        public getSelect2Options() {
            var selec2Options = super.getSelect2Options();

            selec2Options.query = this.queryCustom;
        }

        protected queryCustom(p1: Select2QueryOptions) {
                var term = (Q.isEmptyOrNull(p1.term) ? '' : Select2.util.stripDiacritics(Q.coalesce(p1.term, '')).toUpperCase());

          var results = (this as any).data.filter((item) => {
                  [ADD YOUR LOGIC HERE]
          }

             var res: Select2Result = {
                results: results.slice((p1.page - 1) * 100 /*this.pageSize*/, p1.page * 100/*this.pageSize*/),
                more: results.length >= p1.page * 100/*this.pageSize*/,
                context: p1.context
            }
            p1.callback(res);
        }

Thanks :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Akarsh03 picture Akarsh03  路  3Comments

GitHubOrim picture GitHubOrim  路  3Comments

dudeman972 picture dudeman972  路  3Comments

JohnRanger picture JohnRanger  路  3Comments

StefanTheiner picture StefanTheiner  路  3Comments