Navigating advanced search through nuanced filters dynamically with AngularJS

Here you will find the advanced search form:

https://i.stack.imgur.com/g7Hiz.png

I have successfully created a URL and parameters for document sections, but I am struggling to come up with a solution for managing the "Add Property Restrictions" section which allows the user to add the property up to 5 times.

For example:

https://i.stack.imgur.com/s2Qr8.png

My goal is to handle this situation in AngularJS by implementing addition/deletion options and allowing dynamic changes on the fly. Additionally, I aim to generate the appropriate URL (GET/POST) to send the search data to the API on the backend.

Answer №1

If you want to manage this feature within your model, consider utilizing an array of objects.

Your model's structure could resemble something like this:

let dataModel = {
      'allwords': '',
      'exact_phrase':'',
      /// .. additional basic search model variables

      'property_res': [ {'property':'','action':'contains','value':'','logical_operator':'and'} ]
}

In your template, generate the list of property restrictions dynamically using ng-repeat on dataModel['property_res']

To implement "add property," create a click handler that appends another object (with the same structure as the initial row) to dataModel['property_res']. The ng-repeat directive will handle the rest.

To extract values for your POST request, iterate through the array of dataModel['property_res'] and build your variables. Alternatively, you can JSON.serialize() it and process it on the server side.

I hope this helps you move forward!

EDIT

Here is an example of ng-repeat rendering:

var app = angular.module('app', []);

app.controller('mainController', function($scope, $http) {
    
   $scope.dataModel = {
      'property_res': [ {'property':'','action':'contains','value':'','logical_operator':'and'} ]
   }
   
   $scope.addRow = function(){
      $scope.dataModel['property_res'].push({'property':'','action':'contains','value':'','logical_operator':'and'})
   }
   $scope.showModel= function(){
      console.log($scope.dataModel)
   }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
 
<div ng-app="app">
  <div ng-controller="mainController">
    
     <h1>Property restrictions:</h1>
     <div ng-repeat="ps in dataModel.property_res">
       <select ng-model="ps.property">
         <option value="">Pick property</option>
         <option value="Property 1">Property 1</option>
         <option value="Property 2">Property 2</option>
       </select>
       <select ng-model="ps.action">
         <option value="doesn't contain">doesn't contain</option>
         <option value="contains">contains</option>
         
       </select>
       <input ng-model="ps.value">
       <select ng-model="ps.logical_operator">
         <option value="or">or</option>
         <option value="and">and</option>
         
       </select>
     </div>
     <hr>
     <div><button ng-click="addRow()">Add Row</button></div>
     <hr>
     <div><button ng-click="showModel()">Console Log Model</button></div>
  </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing a checkbox within a select dropdown component in Vue

Has anyone come across a checkbox dropdown feature in Vue? I have been searching online but couldn't find any examples or resources related to this. If someone has a working skeleton for it, please share! ...

Guide to streaming audio files using vue.js

I am attempting to incorporate an audio file into my vue.js project using the following code: import sound from '../../recordings/sound.mp4' const audio = new Audio(sound) audio.play() Although this method works perfectly fine, I have encounter ...

Inserting information into an array: Access the final index consistently with TypeScript

I am interested in dynamically creating a table by allocating it, with the variable nbrBoules: boules:Boule :[] boule:Boule; Boule{id,poids} Method(){ for (var _i = 0; _i < this.nbrBoules; _i++) { this.boule.id = _i; alert(_i); this ...

What is the process for storing an array in AdonisJs migrations?

Having trouble saving an array into a PostgreSQL database! 'use strict' const Schema = use('Schema'); class UsersSchema extends Schema { up () { this.create('users', (table) => { table.increments(); t ...

The interaction between AngularJS ui-router and OAuth2 access_tokens causes conflicts

I have a front-end built using AngularJS with ui-router. In order to interact with the REST API on the backend, I need to obtain an OAuth2 access token through implicit grant. The issue arises during the final step of the OAuth process, when the access to ...

Utilize the function of express

The following code is not behaving as expected: var express = require('express'); var app = express(); app.use(function(req, res, next) { console.log('first statement'); next(); }, function (req, res, next) { console.log('se ...

What is the best way to add both the id and the full object to an array list at the

Requirements: "admin-on-rest": "^1.3.3", "base64-js": "^1.2.1", "react": "^16.2.0", "react-dom": "^16.2.0" I have a User model that includes a List of Roles. // User { id: "abcd1234", name: "John Doe", ... authorities: [ { ...

Conceal one object when the other is revealed?

Is there a way to hide the element with the class .close-button while showing another element with the ID #loading-animation? Can jQuery conditionals help achieve this? For example: if ($('#loading-animation').is(':visible')) { $ ...

What is the Proper Way to Add Inline Comments in JSX Code?

Currently, I am in the process of learning React and I have been experimenting with adding inline comments within JSX. However, when I try to use the regular JavaScript // comments, it leads to a syntax error. Let me share a snippet of my code below: const ...

Utilizing HTML/CSS with React/Bootstrap: A Comprehensive Guide

Looking for help with integrating HTML/CSS code into React/Bootstrap? I need assistance with coding in React using Bootstrap. How do I effectively use components and props? Even after installing bootstrap, I am encountering errors. Is it possible to dire ...

unable to fetch the ID of the checkbox when using the ng-checked directive in AngularJS

My HTML table is populated with data using AngularJs. <tr class="gradeX" ng-repeat="itm in usersList"> <td> <input type="checkbox" ng-checked="itm.checkstatus == 1" ng-mod ...

Error: Unable to access property 'module' of an undefined object in ngRoute

I'm currently working on implementing routing in my project and I'm facing some challenges. Below is the code from my index.html file: <!DOCTYPE html> <!-- Angular Material CSS now available via Google CDN; version 0.11.2 used here - ...

Are there any methods for updating redux-form's submitting property with a workaround?

I have integrated reCAPTCHA v2 with a sign-up form that is using redux-form. The issue I am facing is that when the user submits the form, the reCAPTCHA modal pops up and the redux-form's 'submitting' prop changes from 'false' to & ...

Tips for personalizing text and icon colors in the TableSortText element of Material-ui

My Goal: I aim to empower users with the ability to apply customized styles to my EnhancedTable component by utilizing a styles object containing properties like headCellColor, headCellBackgroundColor, bodyCellColor, bodyCellBackgroundColor, and more. The ...

Encountered a "http://errors.angularjs.org/1.6.5/$injector" error when integrating AngularJS with Laravel

Hello friends, I'm in need of some assistance. I am facing an issue while trying to integrate Laravel with AngularJS. Can anyone provide guidance? "Error: [$injector:modulerr] http://errors.angularjs.org/1.6.5/$injector" To provide more context, I h ...

This page is overwhelmed with an excessive number of active WebGL contexts, resulting in the inevitable loss of the oldest context. Brace yourselves, for the veteran context shall

I am experiencing a strange and perplexing error exclusively in the Safari browser. The cause remains elusive, leaving me puzzled. I have implemented AngularJS 1.3.x in my project. I wonder how I can identify which libraries might be triggering this myst ...

What is the best way to iterate through my array of objects using a forEach loop and assign a value to the property of any object that has an empty string?

Inquiry for Part 1: I am currently exploring the use of forEach loop to iterate through an array of objects. My goal is to update the property "profile_image_url" of objects that have an empty string as its value, setting it to a default link ("/media/arti ...

Experiencing a 404 error when attempting to transmit data from controller.js to a spring controller

I encountered an issue while trying to send an ID to a Spring controller as I kept receiving a 404 error. My setup includes AngularJS, Spring, and MongoDB, where data retrieval works perfectly. The problem arises when passing the ID after clicking on the a ...

Assurance-driven number tally

I'm diving into JavaScript and recently started exploring promises. I've put together a code snippet that logs the value passed to the promise function as a parameter after the setTimeout function is triggered. Now, I'm wondering if there&ap ...

The image slide change feature ceases to function properly when incorporating two separate functions

I have a function that successfully changes the image of a container every 5 seconds. However, I am facing an issue when trying to add 2 containers side by side and change their images simultaneously. When I run the functions for both containers, only one ...