Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to make a field not required with joi

Joi.object().keys({
    contact: Joi.object().keys({
        first_name: Joi.string(),
        last_name: Joi.string(),
        phone: Joi.string(),
    }),
    address: Joi.object().keys({
        place: Joi.string(),
        city: Joi.string().min(2).max(30),
        street: Joi.string(),
        house_number: Joi.string()
    }).when('contact', {
        is: Joi.object().keys({
            first_name: Joi.exist(),
            last_name: Joi.exist(),
            phone: Joi.exist(),
        }),
        then: Joi.object({ place: Joi.required() }).required(),
        otherwise: Joi.object({ place: Joi.forbidden() })
    }),
    passengers_amount: Joi.number(),
    notes: Joi.string()
});
Comment

how to make a field not required with joi

let schema = {};

  let stations = {
    contact: {
      first_name: Joi.string().min(2).max(10).regex(Regex.alphabeta, 'alphabeta').allow("").error(JoiCustomErrors),
      last_name: Joi.string().min(2).max(10).regex(Regex.alphabeta, 'alphabeta').allow("").error(JoiCustomErrors),
      phone: Joi.string().min(10).max(10).regex(Regex.num, 'num').allow("").error(JoiCustomErrors),
    },
    address: {
      place: Joi.string().min(2).max(10).regex(Regex.alphanum, 'alphanum').required().error(JoiCustomErrors),
      city: Joi.string().min(2).max(30).required().error(JoiCustomErrors),
      street: Joi.string().min(2).max(30).regex(Regex.alphabeta, 'alphabeta').required().error(JoiCustomErrors),
      house_number: Joi.string().min(1).max(6).regex(Regex.alphanum, 'alphanum').allow("").error(JoiCustomErrors)
    },
    passengers_amount: Joi.number().min(0).max(4).required().error(JoiCustomErrors),
    notes: Joi.string().min(2).max(100).regex(Regex.alphanum, 'alphanum').allow("").error(JoiCustomErrors)
  };
  schema.stations = Joi.array().items(stations).min(1).max(5).required().error(JoiCustomErrors);
Comment

PREVIOUS NEXT
Code Example
Javascript :: pagination.js cdn 
Javascript :: js method .sort 
Javascript :: animated node with tag 1 does not exist 
Javascript :: how to host a react website 
Javascript :: node js arabic number to english number 
Javascript :: Laravel react 404 routes 
Javascript :: nodejs mysql connection 
Javascript :: transaction commit rollback nodejs 
Javascript :: abstract class in js 
Javascript :: vue route automatic redirect 
Javascript :: implement queue using stack javascript 
Javascript :: how to remove __proto__ from javascript object 
Javascript :: jade cdn 
Javascript :: usestate hook with callback 
Javascript :: uiimage from assets 
Javascript :: add to array applescript 
Javascript :: use effect hook 
Javascript :: GET and CHANGE the class of an element 
Javascript :: alert in javascript 
Javascript :: ForEach Element with Function or Lambda 
Javascript :: conditional operator 
Javascript :: function create array javascript 
Javascript :: directive multiple input 
Javascript :: javascript for each 
Javascript :: lodash sum 
Javascript :: filter buttons react 
Javascript :: javascript return 
Javascript :: median of two sorted arrays 
Javascript :: trim text 
Javascript :: call a javascript function at a specific time of day 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =