The art of efficiently mass-producing entries

For my application, I need users to answer 50 questions. These questions are retrieved through a web service along with their corresponding answers, all assigned to a unique ticket number.

The challenge is in displaying and saving the user's choices. What would be the best practice in this scenario?

I am using TypeScript and Angular for development.

Currently, I have set up a table with 50 rows, each containing a dropdown list for answering a question. The questions are pre-fetched and displayed in the dropdowns.

However, I am struggling with accessing and identifying which questions the users have answered and saved within these 50 records.

My goal is to save all responses at once if all are answered, or individually if needed (although it might not be an ideal solution due to transaction autonomy concerns).

I attempted to use formGroup for the table but encountered issues.

Perhaps my approach with the table structure is incorrect?

Any assistance on this matter would be greatly appreciated!

Answer №1

When considering user experience and project requirements, there are important factors to keep in mind.

For users answering multiple questions, constantly clicking on dropdowns and waiting for answers can be frustrating. To improve this, it's recommended to fetch all questions and related answers in a single http call from the web service and display them in a table or another suitable element.

On the other hand, if users only require a few answers, your current approach is effective. Using Angular with Reactive Forms and FormArray makes it simple to implement. A sample implementation could look like this:

<div *ngFor="let question of questions">
  <button (click)="questionsUnfoldedMap[question.id]">Fold/Unfold</button>
  <p>{{ question.title }}</p>
  <app-related-questions *ngIf="isQuestionUnfolded()" 
                         [relatedAnswers]="relatedAnswersMap[question.id]"
                         (questionAnswered)="onQuestionAnswered(question.id, $event)">
  </app-related-questions>
</div>

In this code snippet, you maintain a map to track folded/unfolded questions and another map to store related answers. When a user answers a question, the data is stored in a form array to be submitted to the server later.

Consider sending all data in a single http call to the web service to streamline the process, especially if all questions will be answered. This avoids making numerous calls to the server for each question.

Answer №2

Thank you for your response. I believe displaying all 50 questions at once is the most optimal solution, with each question having approximately 2-5 answers in a dropdown list.

Here is what I have implemented in HTML:

<div class="row justify-content-center">
    <div class="col-8">
        <form name="editForm" novalidate (ngSubmit)="submit()" #editForm="ngForm">
            <h2 id="jhi--entry-heading">Create or edit an Entry Test</h2>
            <div class="table-responsive" *ngIf="Questions">
                <table class="table table-striped">
                    <thead>
                        <tr jhiSort [(predicate)]="predicate" [(ascending)]="reverse" [callback]="reset.bind(this)">
                            <th jhiSortBy="id"><span>ID</span>
                                <fa-icon [icon]="'sort'"></fa-icon>
                            </th>
                            <th jhiSortBy="name"><span>Question</span>
                                <fa-icon [icon]="'sort'"></fa-icon>
                            </th>
                        </tr>
                    </thead>
                    <tbody infinite-scroll (scrolled)="loadPage(page + 1)" [infiniteScrollDisabled]="page >= links['last']" [infiniteScrollDistance]="0">
                            <tr *ngFor="let Question of Questions ;trackBy: trackId; let i = index;">
                            <th scope="row">{{Question.id}}</th>
                            <td>{{Question.name}} {{Question.description}}</br>
                                      <select class="form-control" id="answerid">
                                        <option disabled hidden [value]="selectUndefinedOptionValue">-- select --</option>
                                        <option *ngFor="let answer of Question.answers; let j = index;" [value]="answer.id">{{answer.description}}</option>
                                    </select>
                            </td>
                        </tr>
                    </tbody>
                    <div>
                        <button type="button" id="cancel-save" class="btn btn-secondary" (click)="previousState()">
                            <fa-icon [icon]="'ban'"></fa-icon>&nbsp;<span>Cancel</span>
                        </button>
                        <button type="submit" id="save-entity" [disabled]="editForm.form.invalid || isSaving" class="btn btn-primary">
                            <fa-icon [icon]="'save'"></fa-icon>&nbsp;<span>Save</span>
                        </button>
                    </div>
        </form>
    </div>

The table functions properly as it retrieves data from the service and allows selection from the drop-down list. However, I am unsure how to access individual records in the table from TypeScript. My goal is to retrieve the selected answer along with its related question. Is there a way to obtain the entire table as one object?

Appreciate your assistance! augeres

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

Encountering an issue during deployment in Azure Web App - File package cannot be located

While attempting to pipeline a job and add it to a web app in the Azure portal, I encountered the following error: No package was found with the specified pattern: D:\a\1\s***.zip Please verify if the package mentioned in the task has been ...

Fade In Effect in Angular 2 Using SwitchCase

Hi everyone, I'm facing an issue with making my switch cases fade in after one is called. Here's what I have so far. When the correct switch case is entered in the input field, I want the current one to fade out and the new one to fade in. How ...

Encountering a SassError while trying to create unique themes with Angular Materials

I'm currently in the process of designing a unique theme for Angular Materials by following the instructions provided in this guide:https://material.angular.io/guide/theming#defining-a-custom-theme However, I've encountered an issue while attemp ...

What is the process for managing multiple selections using checkbox code?

I have been following the official tutorial for ag-grid and I've reached a point where I need to manipulate information related to selected checkboxes. However, the documentation lacks detail on how the code actually functions. It might be understanda ...

Images are failing to load in Ionic 3

Currently working on developing an Ionic application and troubleshooting the use of the camera native plugin. The script functions flawlessly in a fresh project, but encounters issues within the current project environment. Initially suspected a problem w ...

Declaring types globally in Visual Studio Code for JavaScript programming

My /typings/$app.d.ts file has the following structure: declare class App { test: object } export const $app: App; https://i.sstatic.net/3HW7M.png In order to enable intellisense, I have to auto-import it, resulting in a line like this at the begin ...

Customizing Meta tags in Angular SSR based on API response content

Exploring Angular SSR: Updating meta tag data in view based on API response for routing (Stirrl+U) Angular SSR Technique: Dynamically updating and inserting meta tags based on API response data for routing (Stirrl+U) ...

The error occurred due to passing along an 'undefined' value instead of a stream which was expected. Make sure to provide an Observable, Promise, Array, or Iterable. This issue was raised within the context of <Jasmine

Hey, I've implemented this code snippet in ngOnInit for polling, but it's causing all my test cases to fail. Can someone please assist me in resolving this issue? ngOnInit(): void { this.timeInterval = interval(5000) .pipe( startWith(0), sw ...

Implementing Datepicker with ngModel in Angular

I implemented a date picker in my form using the guidelines from this page: <div class="input-group date" data-provide="datepicker" > <input type="text" class="form-control"> <div class=&quo ...

Duplicate Execution Issue with ViewChild Function in Angular

In my application, I have three main components: Nav, App, and Form. Within the Nav component, there is a function that changes the position of CSS, which can be called from both the Nav and App components (triggered by the Form component). However, I am f ...

Exploring depths with Typescript recursion

I'm attempting to implement a recursive search in Typescript, but I am encountering an issue where TS is unable to determine the return type of the function. function findDirectory( directoryId: Key, directory: Directory, ) { if (!directory) ret ...

Ways to assign a default value to a radio button using a mock JSON dataset

As a beginner in AngularJS2, I am looking to resolve an issue where the checkbox is automatically checked when retrieving values from a mock JSON file. Can someone please help me? <div class="form-row"> <div class="formHeading">Skills *< ...

Improving efficiency of API requests to a single endpoint utilizing varied payloads

Currently, I am encountering an issue with an API in a significant Angular Project. Utilizing rxjs 6, the API calculates product costs across multiple dates and cities. This particular API is accessed from numerous components, with 3-4 components calling ...

Navigating through Dynamic URL Parameters with RouterLink in an Angular Application

Within my Angular 2 application, there exists a tab section where users can choose from a collection of separate yet contextually connected components. By clicking on one of these links, the corresponding component is loaded based on the routerLink definit ...

What are some ways to ensure an ion-item is adaptable to various screen sizes?

My goal is to create a responsive ion-item. Instead of the initial layout shown here: (https://i.sstatic.net/9yROA.png) I want it to look more like this: (https://i.sstatic.net/eUkgE.png) You'll notice that some information gets cut off in the fir ...

After upgrading to node version 20 and other dependencies, encountering ERR_REQUIRE_ESM issue

Attempting to update node from version 16 to 20 has led me to also consider upgrading some other libraries simultaneously. Upon trying to start my backend after completing the updates, the following error occurred: % yarn run dev [nodemon] 3.0.1 [nodemon] ...

Does TypeScript lack awareness of type checking within nested functions?

Currently, I am using TypeScript with React and encountering a particular issue. Below is a function I have created to ensure that the variable 'arr' is an Array and not empty. export const isNotEmptyArr = (arr?: unknown[]) => { return Arra ...

I've been working on setting up a navbar in React/typescript that links to various routes, but I've hit a snag - every time I try to create a link

import React from 'react' import { Link } from 'react-router-dom' export default function NavBar() { return ( <div className='NavContainer'> <link to='/home'>Home</link> <l ...

MUI Select component not displaying top border

Can anyone help me understand why the select field is behaving this way? I'm new to the project and suspect that someone may have made changes to it. https://i.sstatic.net/pB6Sx.png <mui.FormControl style={{ width: '598px' }}> ...

Ways to dynamically display components in React Native

In my React Native app, I have a custom tab control that is rendered dynamically using the following configuration: const TABS = [ { title: 'Tab 1', component: MyComponentOne }, { title: 'Tab 2', component: MyComponentTwo } ]; T ...