Validate dates then transfer it to iso string react - validation

My problem is that I need to validate my date using any validation library (joi, yup, superstruct..etc) and after that, I need to cast the date object to iso string
I use Flatpikr , react-hook-form , joi OR yup
This my approach at first glance
Flatpickr >> Date >> Validate >> toISOString() if validation succeed
I tried to achieve the first approach via yup but no hope
I tried to make a pre and post transform in yup
I opened a question in their repository explaining my steps
https://github.com/jquense/yup/issues/1153
My approach in joi didn't succeed also
i used this code
joi
.date()
.iso()
.required()
.min(new Date())
.messages({
'any.required': `Required.`,
'date.format': `Required`,
'date.base': `Should be a type of number`,
'date.min': `The date should be in future`,
});
and i have used
{ convert : false }
in joi options to prevent joi from converting the values
when setting convert to false, all of my validation schemas succeed even if my variables was required or empty

Found an solution by using
.raw()
with joi
refrences :
https://joi.dev/api/?v=17.3.0#anyrawenabled

Related

GraphQL: Validating array elements are in list

I have the following argument in my Ruby GQL:
argument :countryCode, [String], required: false, validates: {inclusion: {in: COUNTRY_CODES}}, prepare: :strip
What I want this to achieve is to allow an array of Strings to be used, and each value in the array to be one of COUNTRY_CODES
However, this returns the exception "is not included in the list". What is wrong here?
Better way for this case create enum with countries, but in this case client must send enum hardcoded country code, other way use validator like dry-validation of similar

How to get url value and compare with input value when using cypress in react project?

how can i get url value param in cypress when I using react and then compare if there are the same value in input field?
Keep in mind that Cypress commands return promise-like objects, so a solution could be:
cy.url().then( url => {
cy.get(inputField).should('have.value',url)
}

How can I use queryBuilders.wrapperQuery base64 encoded string

I have a json string to build a query, and I need to convert this to QueryBuilder. (ES Ver. 6.3.0)
I found that I can use wrapperQuery method, so I wrote this code:
String str = cond.getFilter().toString();
QueryBuilder filter = QueryBuilders.boolQuery().must(QueryBuilders.wrapperQuery(str));
And these are result of variables in debug mode:
This method is working right, as the decription in the Docs(https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wrapper-query.html)
The problem is, that this query just not working.
What is wrong and what should I do?
Any comments would be appreciated. Thanks.
Your JSON format seems to be wrong. Since your ASSET_IP is not a number, it must be string in JSON representation. Hence you need to put it as below in your JSON.
{ "ASSET_IP" : "xx.xxx.xxx.xx" }
Update your JSON with the above and try again.

Azure Logic App toLower string function unknown

Is the documentation for string functions out of date because when I try to use toLower() it i get
"An unknown function with name 'toLower' was found. This may also be a function import or a key lookup on a navigation property, which is not allowed"
I am trying to construct an OData filter to query Dynamics (CRM) - this is the code:
"queries": {"$filter": "concat('hat_',toLower('#{body('Get_record_(Preview)')?['hat_fundname']}')) eq true "}
I think the correct syntax is:
#concat('hat_', toLower(body('Get_record_(Preview)')?['hat_fundname']))

Validate Date FORMAT (not date string) using MomentJS?

I've seen that you can use an ".isValid()" function to check that a given string is in a date format:
moment('2007-05-05', 'YYYY-MM-DD', true).isValid()
But is there a way to confirm that the format is correct? For example:
'YYYY-MM-DD' should return true, but
'YYYY-MM-DDsadsadl' should return false since the characters at the end of the string aren't valid DateTime chars.
We're working on a tool that allows a user to input an existing date format, and then a second input to enter the desired format, but we need validation to ensure the string can properly parse and convert, but they aren't entering a specific date.
The application must accept any and all possible date formats.
Use the following function to validate your format.
validFormat = function(inputFormat){
var validation = moment(moment('2017-06-17').format(inputFormat), inputFormat).inspect();
if(validation.indexOf('invalid') < 0)
return true;
else
return false;
}
Do spend some time to understand this. This simply does a reverse verification using inspect(). The date 2017-06-17 can be replaced by any valid date.
This Moment Js Docs will help you identify the valid formats.
Just make a call to this function as
validFormat('YYYY MM DD')
const getIsValid = inputFormat => moment(moment().format(inputFormat), inputFormat).isValid()
Explanation:
moment().format(inputFormat) - Create a date string from the current time from that format
This is then wrapped with moment() to make that string a moment date object, defining the format to parse it with. Finally we call the isValid() property on that moment date object. This ensures we are able to both create and parse a moment with our custom format.

Resources