npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngform-unsaved-checker

v1.0.2

Published

An npm package for validating conditions and response objects. Ensure data integrity and reliability in your applications with easy-to-use validation functions

Downloads

23

Readme

ngForm-unsaved-checker

unsavedchecker is a function designed to verify whether the data in a form has been altered since it was last submitted or loaded. Its purpose is to compare the current state of the form data with its previous state and determine if any changes have occurred. If changes are detected, the function returns false to indicate that the data has been modified. Otherwise, it returns true, indicating that the data remains unchanged. This function is useful for ensuring data integrity and preventing unintended modifications to form data.

Features

  • Form Data Validation: Validates whether the data in a form has changed since its last submission or loading.
  • Change Detection: Detects modifications made to the form data to maintain data integrity.
  • Boolean Response: Returns a boolean value (true or false) indicating whether changes have occurred.
  • Easy Integration: Simple to integrate into existing codebases or projects.
  • Customizable: Allows for customization to fit specific validation requirements or scenarios.
  • Enhances Data Security: Ensures that only authorized changes are accepted, enhancing data security.
  • Prevents Unintended Modifications: Helps prevent unintended modifications to form data, reducing the risk of errors or data loss.
  • Error Prevention: Facilitates error prevention by alerting users or applications when data has been altered.
  • Lightweight: Lightweight and efficient implementation, minimizing performance overhead.
  • Clear Documentation: Well-documented with clear instructions on usage and integration.
  • Scalable: Scales well for projects of various sizes, from small applications to enterprise-level systems.
  • Tested and Reliable: Thoroughly tested for reliability and robustness to ensure consistent performance.
  • Version Control: Easily managed through version control systems like Git for tracking changes and collaborating with teams.
  • Cross-platform Compatibility: Compatible with a wide range of platforms and frameworks for versatility in development environments.
  • Continuous Support: Provides ongoing support and maintenance to address any issues or updates.

Installation

Install the package via npm:

npm install ngform-unsaved-checker

Usage

Here's a quick example to get you started:

Parameters

  • condition (boolean): Specifies whether to validate form data and response object.
  • formData (object): Object containing form data to be validated.
  • responseObject (optional object, applicable when the first boolean parameter is set to true): Object containing response data to be validated against the form data.
  • strictCheck (boolean, optional): If set to true, performs strict checking of response object keys against form data keys. Default is false.
const validateFormDataAndResponse = require('./validateFormDataAndResponse');

// Example 1: Basic form data validation
const formData = {
    username: 'john_doe',
    password: 'password123'
};
const responseObj = {
    username: 'john_doe',
    password: 'password123'
};
const isValid = validateFormDataAndResponse(true, formData, responseObj);
console.log(isValid); // Output: true

// Example 2: Strict response object key checking
const formData2 = {
    username: 'john_doe',
    password: 'password123'
};
const responseObj2 = {
    username: 'john_doe',
    password: 'password456'
};
const isValid2 = validateFormDataAndResponse(false, formData2, responseObj2, true);
console.log(isValid2); // Output: false

Angular Example: For new form

import { Component } from '@angular/core';
import { validateFormDataAndResponse } from './validateFormDataAndResponse'; // Import the function

@Component({
  selector: 'app-my-form',
  templateUrl: './my-form.component.html',
  styleUrls: ['./my-form.component.css']
})
export class MyFormComponent {
  // New form data (empty)
  formData = {
    username: '',
    password: ''
  };

  isSubmitDisabled = true; // Initially disable the submit button

  constructor() { }

  onSubmit() {
    // Handle form submission
  }

  onInputChange() {
    // Check form validity whenever there's an input change
    this.isSubmitDisabled = !validateFormDataAndResponse(true, this.formData);
  }
}

And the corresponding template (my-form.component.html):

<form (ngSubmit)="onSubmit()">
  <label>Username:</label>
  <input type="text" name="username" [(ngModel)]="formData.username" (input)="onInputChange()">
  <label>Password:</label>
  <input type="password" name="password" [(ngModel)]="formData.password" (input)="onInputChange()">
  <button type="submit" [disabled]="isSubmitDisabled">Submit</button>
</form>

Example: compare with responce

import { Component } from '@angular/core';
import { validateFormDataAndResponse } from './validateFormDataAndResponse'; // Import the function

@Component({
  selector: 'app-my-form',
  templateUrl: './my-form.component.html',
  styleUrls: ['./my-form.component.css']
})
export class MyFormComponent {
  // New form data
  formData = {
    username: 'john_doe',
    password: 'password123'
  };

  // Response object
  responseObject = {
    username: 'john_doe',
    password: 'password123'
  };

  isSubmitDisabled = true; // Initially disable the submit button

  constructor() { }

  onSubmit() {
    // Handle form submission
  }

  onInputChange() {
    // Check form validity whenever there's an input change
    this.isSubmitDisabled = !validateFormDataAndResponse(false, this.formData, this.responseObject);
  }
}

And the corresponding template (my-form.component.html):

<form (ngSubmit)="onSubmit()">
  <label>Username:</label>
  <input type="text" name="username" [(ngModel)]="formData.username" (input)="onInputChange()">
  <label>Password:</label>
  <input type="password" name="password" [(ngModel)]="formData.password" (input)="onInputChange()">
  <button type="submit" [disabled]="isSubmitDisabled">Submit</button>
</form>

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have any questions, please file an issue on the GitHub issues page.

Acknowledgments

Thanks to all the contributors who have helped to make this project better.