### Example RulesJSON Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/types.md A complete example demonstrating a RulesJSON structure with nested groups and various rule types. ```javascript { valid: true, condition: 'AND', rules: [ { id: 'name', field: 'user_name', type: 'string', input: 'text', operator: 'contains', value: 'John' }, { condition: 'OR', rules: [ { id: 'age', field: 'user_age', type: 'integer', input: 'number', operator: 'greater', value: 30 }, { id: 'status', field: 'user_status', type: 'string', input: 'select', operator: 'in', value: ['active', 'pending'] } ] } ] } ``` -------------------------------- ### Install jQuery QueryBuilder with npm Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/README.md Use npm to install the jQuery QueryBuilder package. This is a common method for managing project dependencies. ```bash npm install jQuery-QueryBuilder ``` -------------------------------- ### Extend Filter Configuration with Description Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/plugins.md This example shows how to extend the filter configuration to include a description. This description will be displayed in the UI by the 'filter-description' plugin. ```javascript { id: 'status', label: 'Status', description: 'User account status', // plugin displays this description in UI } ``` -------------------------------- ### Common QueryBuilder Filter Usage Example Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/types.md An example demonstrating a common filter configuration for a 'User Name' field. It specifies the field's ID, backend name, display label, data type, input type, and validation rules. ```javascript { id: 'name', field: 'user_name', label: 'User Name', type: 'string', input: 'text', default_value: '', validation: { min: 1, max: 100, format: '^[a-zA-Z ]+$' } } ``` -------------------------------- ### Import QueryBuilder Rules Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/INDEX.md Shows how to set rules into the QueryBuilder using simple or grouped formats. Includes an example of importing rules from a SQL string. ```javascript // Simple format $('#builder').queryBuilder('setRules', [ {id: 'name', operator: 'equal', value: 'John'}, {id: 'age', operator: 'greater', value: 18} ]); // Group format with nesting $('#builder').queryBuilder('setRules', { condition: 'AND', rules: [ {id: 'name', operator: 'contains', value: 'John'}, { condition: 'OR', rules: [ {id: 'age', operator: 'greater', value: 30}, {id: 'status', operator: 'equal', value: 'active'} ] } ] }); // From SQL (requires sql-support plugin) $('#builder').queryBuilder('sqlToRules', "(name LIKE 'John%') AND (age > 18)"); ``` -------------------------------- ### QueryBuilder afterInit Event Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/events.md Listen for the `afterInit` event, which fires after the builder is fully initialized and just before the root group is created. This is useful for performing actions immediately after setup. ```javascript $('#builder').queryBuilder('on', 'afterInit', function() { console.log('Builder initialized'); }); ``` -------------------------------- ### QueryBuilder Initialization and Method Call Example Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/api-reference.md Demonstrates initializing the QueryBuilder with specific filters and then calling the 'getRules' method on the instance. It also shows how to access the instance directly using jQuery's data method. ```javascript $('#builder').queryBuilder({ filters: [ {id: 'name', label: 'Name', type: 'string'}, {id: 'age', label: 'Age', type: 'integer'} ] }); // Call method on instance $('#builder').queryBuilder('getRules'); // Access the instance directly var instance = $('#builder').data('queryBuilder'); ``` -------------------------------- ### Example: Highlight Invalid Rules Plugin Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/plugins.md This example demonstrates defining a plugin that visually highlights invalid rules. It listens for validation changes and applies/removes a CSS class accordingly. The plugin can be configured with a custom highlight color. ```javascript // Define plugin QueryBuilder.define('highlight-invalid', function(options) { this.on('changer:validate', function(e) { if (!e.value) { this.$el.find('.rule-container').addClass('is-invalid'); } else { this.$el.find('.rule-container').removeClass('is-invalid'); } }); }, { highlight_color: 'red' }); // Use plugin $('#builder').queryBuilder({ plugins: { 'highlight-invalid': { highlight_color: 'orange' } } }); ``` -------------------------------- ### Log Successful Rule Loading Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/events.md Fired after `setRules()` completes. This example logs a message to the console upon successful loading of rules. ```javascript $("#builder").queryBuilder("on", "afterSetRules", function() { console.log("Rules loaded successfully"); }); ``` -------------------------------- ### Catching QueryBuilder Configuration Errors Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/errors.md This example demonstrates how to catch a `ConfigError` that occurs during QueryBuilder initialization due to invalid configuration, such as an empty filters list. It logs the error name and message to the console. ```javascript try { $("#builder").queryBuilder({ filters: [] }); } catch (e) { console.error(e.name, e.message); } ``` -------------------------------- ### Access Plugin Options Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/plugins.md Retrieve plugin options using the getPluginOptions method. You can get all options for a plugin or a specific option by its key. ```javascript var qb = $('#builder').data('queryBuilder'); var options = qb.getPluginOptions('plugin-name'); var option = qb.getPluginOptions('plugin-name', 'option1'); ``` -------------------------------- ### Add and Remove Filters Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/examples/index.html Dynamically modifies the available filters in the query builder. This example adds a new filter and removes existing ones. ```javascript // set filters $('.set-filters').on('click', function() { $(this).prop('disabled', true); bootstrap.Tooltip.getInstance($(this)).hide(); // add a new filter after 'state' $('#builder').queryBuilder('addFilter', { id: 'new_one', label: 'New filter', type: 'string' }, 'state' ); // remove filter 'coord' $('#builder').queryBuilder('removeFilter', ['coord', 'state', 'bson'], true ); // also available : 'setFilters' }); ``` -------------------------------- ### Manage QueryBuilder Rules and Groups Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/INDEX.md Provides examples for managing rules within the QueryBuilder, including resetting, clearing, adding, deleting rules, and adding/deleting subgroups. ```javascript // Reset to one empty rule $('#builder').queryBuilder('reset'); // Clear all rules $('#builder').queryBuilder('clear'); // Add rule to group var root = $('#builder').queryBuilder('getModel'); $('#builder').queryBuilder('addRule', root); // Delete rule var rule = $('#builder').queryBuilder('getModel', $('.rule-container').first()); $('#builder').queryBuilder('deleteRule', rule); // Add subgroup var newGroup = $('#builder').queryBuilder('addGroup', root); // Delete subgroup $('#builder').queryBuilder('deleteGroup', newGroup); ``` -------------------------------- ### Get Query Rules Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/README.md Retrieve the current set of rules from the query builder instance. This is useful for saving or processing the query. ```javascript var rules = $('#builder').queryBuilder('getRules'); console.log(JSON.stringify(rules)); ``` -------------------------------- ### Listen to QueryBuilder Events with jQuery Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/events.md Demonstrates multiple ways to attach event listeners to the QueryBuilder instance using jQuery's `.on()` method, the queryBuilder's `on()` method, and direct instance method calls. Includes a one-time listener example. ```javascript $('#builder').on('afterAddRule.queryBuilder', function(e, rule) { console.log('Rule added:', rule); }); ``` ```javascript $('#builder').queryBuilder('on', 'afterAddRule', function(e, rule) { console.log('Rule added:', rule); }); ``` ```javascript var qb = $('#builder').data('queryBuilder'); vqb.on('afterAddRule', function(e, rule) { console.log('Rule added:', rule); }); ``` ```javascript $('#builder').queryBuilder('once', 'afterSetRules', function() { console.log('Rules loaded once'); }); ``` -------------------------------- ### Set and Get QueryBuilder Defaults Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/api-reference.md Use QueryBuilder.defaults to set global default configurations for all new QueryBuilder instances or to retrieve specific default options or the entire defaults object. ```javascript $.fn.queryBuilder.defaults({ allow_empty: true, default_condition: 'OR' }); // Get specific default option var allowEmpty = $.fn.queryBuilder.defaults('allow_empty'); // Get full defaults object var allDefaults = $.fn.queryBuilder.defaults(); ``` -------------------------------- ### once(type, callback) Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/api-reference.md Attaches an event listener that fires only once, then is automatically removed. This is useful for one-time setup or actions that should only occur the first time an event is triggered. ```APIDOC ## once(type, callback) ### Description Attaches an event listener that fires only once, then is automatically removed. ### Method ```javascript once(type, callback) ``` ### Parameters #### Path Parameters - **type** (string) - Required - Event type - **callback** (function) - Required - Handler function ### Returns - **QueryBuilder** - this (for chaining) ### Example ```javascript $("#builder").queryBuilder('once', 'afterSetRules', function() { console.log('Rules loaded once'); }); ``` ``` -------------------------------- ### QueryBuilder.defaults(options) Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/api-reference.md Gets or modifies the default configuration for all new QueryBuilder instances. It can be used to set global default options or retrieve specific default values or the entire defaults object. ```APIDOC ## QueryBuilder.defaults(options) ### Description Gets or modifies the default configuration for all new instances. ### Method Static ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **options** (object | string) - Optional - Configuration object to merge with defaults, or a property name to retrieve ### Request Example ```javascript // Set defaults for all new instances $.fn.queryBuilder.defaults({ allow_empty: true, default_condition: 'OR' }); // Get specific default option var allowEmpty = $.fn.queryBuilder.defaults('allow_empty'); // Get full defaults object var allDefaults = $.fn.queryBuilder.defaults(); ``` ### Response #### Success Response (200) - **Configuration object/value** (object | *) - Configuration object/value (if getting) - **undefined** - undefined (if setting) #### Response Example ```json { "allow_empty": true, "default_condition": "OR" } ``` ``` -------------------------------- ### Save and Load Rules via AJAX Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/advanced-usage.md Save rules to the server by sending a JSON payload to a POST endpoint. Load rules from the server by making a GET request to retrieve rules and then setting them in the query builder. ```javascript // Save rules to server function saveRules() { var rules = $('#builder').queryBuilder('getRules'); $.ajax({ url: '/api/queries', method: 'POST', data: JSON.stringify(rules), contentType: 'application/json', success: function(response) { alert('Rules saved successfully'); } }); } // Load rules from server function loadRules(id) { $.ajax({ url: '/api/queries/' + id, method: 'GET', success: function(rules) { $('#builder').queryBuilder('setRules', rules); } }); } ``` -------------------------------- ### Enable Plugins with Object Format and Options Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/configuration.md Configure plugins and their specific options by passing an object to the 'plugins' configuration. An empty object enables the plugin with default settings. ```javascript // Object format with options $('#builder').queryBuilder({ plugins: { 'sql-support': { boolean_as_integer: false }, 'sortable': {} } }); ``` -------------------------------- ### SQL Export with Plugin Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/README.md Initialize the query builder with the 'sql-support' plugin to enable SQL export functionality. Then, retrieve the rules formatted as SQL. ```javascript $('#builder').queryBuilder({ plugins: ['sql-support'] }); var sql = $('#builder').queryBuilder('getRulesAsSQL'); // Execute on backend ``` -------------------------------- ### Basic Initialization Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/README.md Initialize the query builder with a list of filters. Use this to set up the available fields and their types for building queries. ```javascript $('#builder').queryBuilder({ filters: [ {id: 'name', label: 'Name', type: 'string', input: 'text'}, {id: 'age', label: 'Age', type: 'integer', input: 'number'} ] }); ``` -------------------------------- ### Get Rules as JSON Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/examples/index.html Retrieves the current set of rules from the QueryBuilder and displays them as a formatted JSON string. ```javascript $('.parse-json').on('click', function() { $('#result').removeClass('d-none') .find('pre').html(JSON.stringify( $('#builder').queryBuilder('getRules', { get_flags: true, skip_empty: true }), undefined, 2 )); }); ``` -------------------------------- ### Enable Plugins with Array Format Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/configuration.md Activate multiple plugins by providing their names in an array to the 'plugins' configuration option. ```javascript // Array format $('#builder').queryBuilder({ plugins: ['sql-support', 'bt-tooltip-errors'] }); ``` -------------------------------- ### Get Filter by ID Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/api-reference.md Retrieves a filter configuration object by its ID. Use this to access specific filter settings. ```javascript var filter = $('#builder').queryBuilder('getFilterById', 'name'); console.log(filter.label); ``` -------------------------------- ### Initialize QueryBuilder with Options Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/configuration.md Basic initialization of the QueryBuilder plugin by passing an options object to the constructor. Use this to set initial filters and control basic behavior like allowing empty root groups. ```javascript $('#builder').queryBuilder({ filters: [...], allow_empty: false, // ... more options }); ``` -------------------------------- ### Initialize QueryBuilder and Handle Events Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/INDEX.md Basic initialization of the QueryBuilder with filters. Shows how to add an event listener for rule changes and retrieve current rules. ```javascript // Basic initialization $('#builder').queryBuilder({ filters: [ {id: 'name', label: 'Name', type: 'string', input: 'text'}, {id: 'age', label: 'Age', type: 'integer', input: 'number'} ] }); // Add event listener $('#builder').queryBuilder('on', 'afterSetRules', function() { console.log('Rules loaded'); }); // Get current rules var rules = $('#builder').queryBuilder('getRules'); console.log(JSON.stringify(rules)); ``` -------------------------------- ### Translate Text Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/api-reference.md Returns a translated string from the language definitions. Use this to get localized labels for conditions, operators, or error messages. ```javascript var conditionLabel = $('#builder').queryBuilder('translate', 'conditions', 'AND'); var errorMsg = $('#builder').queryBuilder('translate', 'errors', 'empty_group'); ``` -------------------------------- ### Get Root Group Model Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/api-reference.md Retrieves the root group model object for the query builder. This is the top-level container for all rules and groups. ```javascript // Get root group var root = $('#builder').queryBuilder('getModel'); ``` -------------------------------- ### Prevent Adding Group at Max Depth Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/events.md Fired before a subgroup is added. This example prevents adding a group if the nesting level reaches 3. ```javascript $("#builder").queryBuilder("on", "beforeAddGroup", function(e, parent, addRule, level) { if (level >= 3) { e.preventDefault(); alert("Maximum nesting depth reached"); } }); ``` -------------------------------- ### Use a QueryBuilder Plugin (Object Format) Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/plugins.md Activate a registered plugin with custom options by specifying it in the 'plugins' configuration as an object. ```javascript // Object format (with custom options) $('#builder').queryBuilder({ plugins: { 'plugin-name': { option1: 'value1' } } }); ``` -------------------------------- ### afterInit Event Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/events.md Fired when the builder is fully initialized, just before the root group is created. This event does not accept any parameters. ```APIDOC ## afterInit Event ### Description Fired when the builder is fully initialized, just before the root group is created. ### Parameters None ### Example ```javascript $('#builder').queryBuilder('on', 'afterInit', function() { console.log('Builder initialized'); }); ``` ``` -------------------------------- ### Use a QueryBuilder Plugin (Array Format) Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/plugins.md Activate a registered plugin using the 'plugins' configuration option in an array format, which applies default plugin options. ```javascript // Array format (uses default options) $('#builder').queryBuilder({ plugins: ['plugin-name'] }); ``` -------------------------------- ### Get Operator by Type Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/api-reference.md Retrieves an operator configuration object by its type. Useful for inspecting operator properties like the number of inputs required. ```javascript var operator = $('#builder').queryBuilder('getOperatorByType', 'contains'); console.log(operator.nb_inputs); // 1 ``` -------------------------------- ### Get Specific Rule/Group Model Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/api-reference.md Retrieves the model object (Rule or Group) associated with a specific DOM element within the query builder. ```javascript // Get model from DOM element var $rule = $('#builder').find('.rule-container').first(); var rule = $('#builder').queryBuilder('getModel', $rule); ``` -------------------------------- ### Configure and Use QueryBuilder Plugins Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/INDEX.md Demonstrates how to enable and configure plugins for jQuery QueryBuilder, such as SQL support, sortable, and tooltips. Plugin features can be accessed after enabling. ```javascript // Enable plugins $('#builder').queryBuilder({ plugins: { 'sql-support': {}, 'sortable': {}, 'bt-tooltip-errors': {} } }); // Use plugin features var sql = $('#builder').queryBuilder('getRulesAsSQL'); // Configure plugin $('#builder').queryBuilder({ plugins: { 'chosen-selectpicker': { allow_single_deselect: true, width: '100%' } } }); ``` -------------------------------- ### Define and Use a Custom jQuery QueryBuilder Plugin Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/INDEX.md Demonstrates how to define a custom plugin for jQuery QueryBuilder, including adding methods, listening to events, and applying styles. Shows how to instantiate the builder with the custom plugin. ```javascript QueryBuilder.define('my-plugin', function(options) { // Add method to builder instance this.myCustomMethod = function() { return 'custom result'; }; // Listen to events this.on('afterAddRule', function(e, rule) { console.log('Rule added:', rule.id); }); // Add styles or features this.$el.addClass('has-my-plugin'); }, { // Default options option1: 'default_value' }); // Use plugin $('#builder').queryBuilder({ plugins: { 'my-plugin': { option1: 'custom_value' } } }); ``` -------------------------------- ### Constructor Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/DOCUMENTATION_MANIFEST.txt Initializes a new instance of the QueryBuilder on a target DOM element. Accepts an options object to configure its behavior. ```APIDOC ## Constructor ### Description Initializes a new instance of the QueryBuilder on a target DOM element. Accepts an options object to configure its behavior. ### Method JavaScript (jQuery plugin) ### Endpoint N/A (jQuery plugin) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript $("#builder").queryBuilder(options); ``` ### Response #### Success Response (200) N/A (initialization) #### Response Example N/A ``` -------------------------------- ### Core Methods Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/INDEX.md Provides methods for managing the builder's lifecycle, state, and configuration. ```APIDOC ## Core Methods ### Description Methods for cleaning up, resetting, clearing, modifying options, validating, exporting/importing rules, and accessing the rule/group model. ### Methods - `destroy()`: Clean up and remove builder. - `reset()`: Clear and reset to initial state. - `clear()`: Remove all rules. - `setOptions(options)`: Modify configuration at runtime. - `validate()`: Check all rules are valid. - `getRules()`: Export rules as JSON. - `setRules(rules)`: Import rules from JSON. - `getModel(element)`: Get Rule/Group model from DOM. ``` -------------------------------- ### Initialize QueryBuilder with Configuration Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/api-reference.md Use this snippet to initialize the QueryBuilder plugin with a set of filters. The configuration object is passed as the first argument to the jQuery plugin. ```javascript $.fn.queryBuilder(option, ...args) ``` -------------------------------- ### Get Applicable Operators for a Filter Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/api-reference.md Returns a list of operators that are applicable to a given filter. This is useful for dynamically updating UI elements based on filter type. ```javascript var filter = $('#builder').queryBuilder('getFilterById', 'age'); var operators = $('#builder').queryBuilder('getOperators', filter); operators.forEach(function(op) { console.log(op.type, op.label); }); ``` -------------------------------- ### Prevent Adding Rule with beforeAddRule Event Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/events.md Use the 'beforeAddRule' event to intercept rule additions. This example prevents adding more than 10 rules to a group by calling `e.preventDefault()`. ```javascript $("#builder").queryBuilder("on", "beforeAddRule", function(e, parent) { if (parent.rules.length >= 10) { e.preventDefault(); alert("Maximum 10 rules per group"); } }); ``` -------------------------------- ### Instance Methods Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/DOCUMENTATION_MANIFEST.txt Provides access to 40+ methods that operate on a QueryBuilder instance, allowing manipulation of rules, groups, and other aspects of the builder. ```APIDOC ## Instance Methods ### Description Provides access to 40+ methods that operate on a QueryBuilder instance, allowing manipulation of rules, groups, and other aspects of the builder. ### Method JavaScript (jQuery plugin instance methods) ### Endpoint N/A (jQuery plugin instance methods) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript var builder = $("#builder").queryBuilder('getRules'); ``` ### Response #### Success Response (200) Depends on the method called. #### Response Example Depends on the method called. ``` -------------------------------- ### Get Validation Errors from DOM Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/errors.md Retrieves validation errors associated with a specific rule element in the DOM. The error is returned as an array containing the error code and its parameters. ```javascript var $rule = $('#builder').find('.rule-container').first(); var rule = $('#builder').queryBuilder('getModel', $rule); if (rule.error) { console.log('Rule error:', rule.error); // error is array: [error_code, ...params] } ``` -------------------------------- ### Utils.fmt(str, args) Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/advanced-usage.md Formats a string by replacing numbered placeholders (e.g., {0}, {1}) with corresponding values from an array or arguments object. Useful for dynamic string creation. ```APIDOC ## Utils.fmt(str, args) ### Description Formats a string by replacing numbered placeholders with arguments. ### Parameters #### Path Parameters * **str** (string) - Required - String with {0}, {1}, etc. placeholders. * **args** (array | arguments) - Required - Values to substitute. ### Request Example ```javascript Utils.fmt('{0} is {1}', ['John', 'tall']); ``` ### Response #### Success Response - **formatted_string** (string) - The string with placeholders replaced by arguments. ### Response Example ``` John is tall ``` ``` -------------------------------- ### QueryBuilder Class Constructor Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/api-reference.md Illustrates the direct instantiation of the QueryBuilder class, requiring a jQuery-wrapped DOM element and an optional options object for configuration. ```javascript new QueryBuilder($el, options) ``` -------------------------------- ### Configure Custom Input Filter with Getter/Setter Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/INDEX.md Define a filter with a custom input element, specifying functions to get and set its value. Use for complex or non-standard input fields. ```javascript { id: 'custom', type: 'string', input: function(rule, $input) { return ''; }, valueGetter: function(rule) { return rule.$el.find('input').val(); }, valueSetter: function(rule, value) { rule.$el.find('input').val(value); } } ``` -------------------------------- ### Define a Basic Custom Plugin Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/plugins.md Use `QueryBuilder.define` to create a new plugin. This function accepts the plugin name, a callback for instance methods and event handlers, and an optional object for default options. ```javascript QueryBuilder.define('my-plugin', function(options) { // this = QueryBuilder instance // Add methods this.myMethod = function() { // Method code }; // Attach event handlers this.on('afterAddRule', function(e, rule) { // Handler code }); }, { // Default options option1: 'default_value' }); ``` -------------------------------- ### Silent Mode for Rules Parsing Errors Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/errors.md This example shows how to use silent mode to log invalid data instead of throwing an error during setRules. This is useful for non-critical data validation. ```javascript // Silent mode logs errors instead of throwing $('#builder').queryBuilder('setRules', invalidData, { allow_invalid: true }); // Invalid data is logged but doesn't throw ``` -------------------------------- ### Global Error Handling with Try-Catch Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/_autodocs/errors.md Use a try-catch block to handle errors during the initialization of the query builder. ```javascript try { $('#builder').queryBuilder(config); } catch (e) { console.error('Configuration failed:', e.name, e.message); } ``` -------------------------------- ### Initialize QueryBuilder with Options Source: https://github.com/mistic100/jquery-querybuilder/blob/dev/examples/index.html Initializes the jQuery QueryBuilder plugin with a set of predefined filter options. ```javascript var options = { filters: [ { id: 'rate', label: 'Rate', icon: 'bi-box-arrow-lightning-charge-fill', type: 'integer', validation: { min: 0, max: 100 }, plugin: 'slider', plugin_config: { min: 0, max: 100, value: 0 }, valueSetter: function(rule, value) { var input = rule.$el.find('.rule-value-container input'); input.slider('setValue', value); input.val(value); // don't know why I need it } }, /* * placeholder and regex validation */ { id: 'id', label: 'Identifier', icon: 'bi-sunglasses', type: 'string', optgroup: 'plugin', placeholder: '____-____-____', size: 14, operators: ['equal', 'not_equal'], validation: { format: /^.{4}-.{4}-.{4}$/, messages: { format: 'Invalid format, expected: AAAA-AAAA-AAAA' } } }, /* * custom input */ { id: 'coord', label: 'Coordinates', icon: 'bi-star', type: 'string', default_value: 'C.5', description: 'The letter is the cadran identifier:\