• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Czy wprowadzana wartość już istnieje w tabeli

0 głosów
121 wizyt
pytanie zadane 9 kwietnia 2018 w JavaScript przez lastavenger Obywatel (1,060 p.)

Witam, 

Działam w React native i mam problem z sprawdzeniem, czy wprowadzana wartość email nie istnieje już czasem w tabeli, jeśli tak to nie dodawać i wyświetlić powiadomienie. Zacząłem powoli kombinować, ale niestety bez większych skutków. Poniżej dodaje to co mam aktualnie.

addSingleUser = (e) => {
    e.preventDefault();
    let name = this.firstNameInp.value;
    let email = this.emailInp.value;
    let errorCont = document.getElementById("errorSm");
    let errorSmall = document.getElementById("errorContentSm");
    let submitBtn = document.getElementById("submitBtn");

    let i = this.state.contacts.length - 1;
    let emailUp = this.emailInp.value.toUpperCase();

    for (i; i >= 0; i--) {

      let arrUp = this.state.contacts[i].email.toUpperCase();

      if (arrUp.includes(emailUp)) {
        document.getElementById("error").style.display = "flex";
        document.querySelector(".alertICont").style.border = "2px solid #f00";
        document.querySelector(".errorCont .alertICont span").style.color = "#f00";
        document.getElementById("errorContent").innerText = "E-mail already on list";

        this.setState({
          isDoubled: 1
        });
        this.inputToggle();
        break;
      } else {
        
      }
    }

    if (this.state.contacts.length < 10) {

      this.firstNameInp.value = '';
      this.emailInp.value = '';
      document.getElementById('btnR').style.display = 'none';
      document.getElementById("emptyInfo").style.display = "none";

      const users = Object.assign([], this.state.contacts);
      users.push({
        name: name,
        email: email
      });
      this.setState({
        contacts: users
      });
      document.getElementById("add").style.animation = "btnAdd .3s";
      //show error

      document.getElementById("error").style.display = "flex";
      document.querySelector(".alertICont").style.border = "2px solid #04ab6b";
      document.querySelector(".errorCont .alertICont span").style.color = "#04ab6b";
      document.getElementById("errorContent").innerText = "User added";

      fetch(this.state.url, {
        method: 'POST',
        headers: {
          'Content-type': 'application/json'
        },
        body: JSON.stringify({ name: name, email: email })
      })
        .then(resp => resp.json())
        .then(data => console.log(data))
        .catch(error => console.log("error: ", error))

      this.inputToggle();
    } else {
      submitBtn.setAttribute("disabled", "disabled");

      errorCont.style.display = "block";
      errorSmall.innerText = "List has reached maximum";
      setTimeout(function () {
        submitBtn.removeAttribute("disabled");
        errorCont.style.display = "none";
        errorSmall.innerText = "";
      }, 3000)
      this.setState({
        emailDoubled: false
      });
    }
  }

 

Zaloguj lub zarejestruj się, aby odpowiedzieć na to pytanie.

Podobne pytania

0 głosów
2 odpowiedzi 377 wizyt
pytanie zadane 12 stycznia 2019 w Java przez BulweR Nowicjusz (180 p.)
0 głosów
2 odpowiedzi 365 wizyt
pytanie zadane 12 czerwca 2017 w JavaScript przez ShiroUmizake Nałogowiec (46,300 p.)

93,600 zapytań

142,524 odpowiedzi

322,993 komentarzy

63,085 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj

Kursy INF.02 i INF.03
...