This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const JoinedDetails = users.map(user => { | |
return { | |
name: user.name, | |
age: user.age, | |
country_id: countries.map(country => user.country_id == country.country_id ? | |
country.country_name : "") | |
} | |
}) | |
console.log(JoinedDetails); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const users = [ | |
{ "name": "Isaac", "age": 29, "country_id": 30 }, | |
{ "name": "Jessica", "age": 23, "country_id": 41 }, | |
{ "name": "Eva", "age": 25, "country_id": 38 } | |
] | |
const countries = [ | |
{ "country_name": 'Uganda', "country_id": 38 }, | |
{ "country_name": 'Kenya', "country_id": 41 }, | |
{ "country_name": 'Rwanda', "country_id": 30 } | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
<style> | |
html, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="row"> | |
<div class="offset-md-3 col-md-6 mt-5"> | |
<h3>Article Form</h3> | |
<form action="#" @submit.prevent="submitData"> | |
<div class="form-group"> | |
<input | |
type="text" | |
class="form-control" | |
placeholder="Title" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="row"> | |
<div class="offset-md-3 col-md-6 mt-5"> | |
<h3>Article Form</h3> | |
<form action="#" @submit.prevent="submitData"> | |
<div class="form-group"> | |
<input | |
type="text" | |
class="form-control" | |
placeholder="Title" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="row"> | |
<div class="offset-md-3 col-md-6 mt-5"> | |
<h3>Article Form</h3> | |
<form action="#" @submit.prevent="submitData"> | |
<div class="form-group"> | |
<input | |
type="text" | |
class="form-control" | |
placeholder="Title" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
submitData() { | |
ArticleSchema.validate(this.article, { abortEarly: false }) | |
.then(() => { | |
const submittedData = `${this.article.title} ${this.article.description}`; | |
alert(submittedData); | |
}) | |
.catch((err) => { | |
err.inner.forEach((error) => { | |
this.errors = { ...this.errors, [error.path]: error.message }; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
methods: { | |
submitData() { | |
const submittedData = `${this.article.title} ${this.article.description}`; | |
alert(submittedData); | |
}, | |
validate(field) { | |
ArticleSchema.validateAt(field, this.article) | |
.then(() => (this.errors[field] = "")) | |
.catch((err) => { | |
this.errors[err.path] = err.message; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data() { | |
return { | |
article: { | |
title: "", | |
description: "", | |
}, | |
errors: { | |
title: "", | |
description: "" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
import * as Yup from "yup"; | |
const ArticleSchema = Yup.object().shape({ | |
title: Yup.string() | |
.min(10, "Title should be less than 10 characters") | |
.max(100, "Title should not exceed 100 characters") | |
.required("Title is required"), | |
description: Yup.string() | |
.min(50, "Description should be less than 50 characters") |