The data entered is not being forwarded to the firebase database

I am working on an angular material form in my project.

The file I am working on is add-beer.component.html

        <mat-form-field>
            <input type="number" name="mSladu" matInput placeholder="Hmotnosť sladu" #beerMSLadu="ngModel" [(ngModel)]="beer.mSladu">          
        </mat-form-field>
        <mat-form-field>
            <input type="number" name="hRmutu" matInput placeholder="Hustota rmutu" #beerHRmutu="ngModel" [(ngModel)]="beer.hRmutu">
        </mat-form-field>
        <mat-form-field>
            <input type="number" name="predOHlNalevu" matInput placeholder="Predpokladaný objem hl. nálevu" #beerPredOHlNalevu="ngModel" [(ngModel)]="beer.predOHlNalevu" [value]="beer.hRmutu * beer.mSladu">
        </mat-form-field>
        <mat-form-field>
            <input type="number" name="predOPredku" matInput placeholder="Predpokladaný objem predku" #beerPredOPredku="ngModel" [(ngModel)]="beer.predOHlNalevu * 1.3">
        </mat-form-field>

A function called onSubmit within the add-beer.component.ts file, which gets triggered when the form is submitted.

onSubmit({value, valid}: { value: Beer, valid: boolean }) {
    if (!valid) {
        // Show error
        this.flashMessage.show('Prosím zadajte povinné údaje', {
            cssClass: 'alert-warn', timeauto: 4000
        });
    } else {
        // Add new client
        this.beerService.newBeer(value);
        // Show message
        this.flashMessage.show('Údaje boli uspešne uložené', {
            cssClass: 'alert-success', timeauto: 4000
        });
        // Redirect to dashboars
        this.router.navigate(['/']);
    }
}

Within the beer.service.ts

newBeer(beer: Beer) {
this.beersCollection.add(beer);

}

Question 1

In the input fields named mSladu and hRmutu, the values are multiplied and the result is saved as the Value of input. However, when I submit the form, only the mSladu and hRmutu values get saved in Firebase.

Question 2

When I try to multiply the value of the predOHlNalevu field to show it as the value of the predOPredku field, nothing happens and the input remains empty.

Thank you for any assistance provided.

Edit: In the add-beer.component.ts file, I have initialized an object:

beer: Beer = {
    mSladu: null,
    hRmutu: null,
    predOHlNalevu: null,
    predOPredku: null
};

The model Beer.ts contains data structure for Beer[] array.

Answer №1

Refreshing Beer App

export class BeerEnthusiast {
    tasteBitterness: number;
    hopIntensity: number;
    aromaToLeft: number;
    aromaToFront: number;

    constructor() {}
}

...

onSubmit() {
    if (!valid) {
beer: CraftBeer = new CraftBeer()
beer.tasteBitterness = 'getFormValue'; 
beer.hopIntensity = 'getFormValue';
beer.aromaToLeft = 'getFormValue';
beer.aromaToFront = 'getFormValue';
...
this.beerService.brewNewBeer(beer);
...
 }
}

If you prefer using a BrewingForm for your form, then you can replace 'getFormValue' above with this line:

this.yourBrewingForm.get('tasteBitterness').value,

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

Strategies for redirecting search queries when adding a new path

Issue I am facing a challenge with pushing a new path to the URI while maintaining existing search queries. For example: Current URL: https://example.com/foo?bar=123&foobar=123 When I use history.push('newPath'), I end up with https://exa ...

Tips for integrating an HTML template into a React project

I'm finding it challenging to integrate an HTML template into React. The template I am using is for an admin dashboard with multiple pages. I have successfully copied and pasted the HTML code into JSX files and fixed any syntax issues. Here's wh ...

The iFrame that is generated dynamically becomes null when accessed from a page that has been loaded using JQuery

One issue I am facing is with a dynamically created iframe in regular javascript. It functions perfectly fine when called from a static page using conventional methods. However, when it is being called from a page loaded by jQuery, I encounter an error s ...

Guide to smoothly scroll to the top of an element containing collapsible panels using Jquery

I've encountered an issue with a series of divs that are set to toggle the state of a collapsible div upon clicking (similar to an accordion widget). The functionality works as intended, but I'm facing a challenge - I want the page to scroll to t ...

The Power of AngularJS Directives in Harnessing jQuery DOM Event Bindings

I have developed a new directive and have some doubts about the binding syntax like element.bind("click", function(){}). Every time the link function of the directive is called, it creates a duplicate binding. What is the best Angular approach to handle th ...

An array in Javascript that contains sub-arrays within its keys

I am encountering an issue with my array structure. The main array contains sub-arrays and uses custom keys as identifiers. However, I am unable to access the array using these keys. For example, when I try to get the length of the array, it returns 0 even ...

Issue with uploading files on the generated client code

I have come across a straightforward input element that allows users to select a file from their local drive: <input type="file" (change)="onUpload($event)" required/> Once a file is selected, the goal is to upload it to the server. To achieve thi ...

The functionality of the 'treeNodeFullTemplate' in the angular-tree-component is not easily understood

I have been attempting to utilize the #treeNodeFullTemplate in my application to fully customize the component. However, I am encountering an issue where my data is not displaying after implementing the new template as outlined here. Since my data does no ...

What is the best way to manage communication with a database in a Node.js application?

I have a specific structure in my Express app: There is a db helper that I use to interact with my MariaDB database Here is the code snippet: var MariaSQL = require('mariasql'); var db = new MariaSQL(); var queries = { getUserByID : &a ...

Open the .exe file using an HTML link in Firefox browser

While working on a project using php / js / html, I encountered the need to launch a C# application from my web page without requiring any downloads. The challenge was that I primarily use Mozilla Firefox and could only find solutions involving ActiveXOb ...

Incorporate anchor or data-filter into the URL for better functionality

Is there a way to set up a button in a menu that sorts items listed below it? For example, let's say the button is labeled "news". Using the data-filter attribute or another method of identification, can I navigate to a specific page with this button ...

Guide to extracting the values from a newly added table row with the onchange event

Seeking help for a complex issue I'm facing with my ajax function. The function retrieves data from a database and appends it to a table, sometimes resulting in multiple rows being appended due to multiple records retrieved. My challenge is extracting ...

Locating the top 3 largest values in an HTML data table and highlighting them in red

Issue Description: I am working with data that displays the electricity consumption of different buildings in HTML tables. There is a possibility that these tables may contain duplicate values. With the use of jQuery, I am seeking a method to identify an ...

Using {children} in NextJS & Typescript for layout components

I am looking to develop a component for my primary admin interface which will act as a wrapper for the individual screens. Here is the JavaScript code I have: import Header from '../Header' function TopNavbarLayout({ children }) { return ...

The process of generating a querystring from a form using jQuery is not functioning as expected

I am attempting to send an AJAX request, but I am facing an issue where the query string I am trying to construct turns out to be empty. <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>This project dem ...

Utilize AngularJS to Access Global JavaScript Variables

I recently encountered a situation where I needed to incorporate some dynamic functionality into a website I was building. This led me to AngularJS, which I decided to integrate into certain parts of the site rather than the entire thing. Within my JavaSc ...

Steps for deploying an ejs website with winscp

I have developed a Node.js web application using ExpressJS, with the main file being app.js. Now I need to publish this website on a domain using WinSCP. However, WinSCP requires an index.html file as the starting point for publishing the site. Is there ...

Generating a dropdown menu in HTML using JSON entities

I am attempting to populate an HTML Select element with data retrieved from JSON. Below is a simplified version of the JSON object: {"Group1": "TestGroup1", "Group2" : "TestGroup2", "TotGroups" : "2"} To achieve this, I am using JQuery and AJAX for fetch ...

Trouble with fetching data from input fields using jQuery

I am having trouble retrieving values from the input fields. When I use an alert box, it shows that there are no values. I have reviewed my code and I can't seem to find any errors. Could it be that I forgot to include something in my code? <div c ...

Retrieve information from a row by clicking on it, then present it in a dialog box for editing

I'm working on a project using Angularjs to retrieve data from a table row when it's clicked and then display the data in an editable dialog box. I need help with implementing this feature. Here is my current progress: <table> ...