Flutter, Input allow Regex [.](full stop) unlimited typing - regex

I want to allow only [.] unlimited, but why is there over limit 2charactor auto clear?
TextFieldWidget(
controller: controller,
onChanged: (newValue) {
_cubit.onTextChange();
},
inputFormatters: FilteringTextInputFormatter.allow(RegExp(r"[.]+")),
),
image
please view video
I expected to typing [.] unlimited.

Related

NgRx how to dispatch 2 actions in order

I cant seem to find a way with the NgRx (not RxJS Style) to dispatch 2 Actions in an effect.
I would like to (IN THIS ORDER):
delete a Movie in the Database with an effect,
dispatch deleteMovieSuccess
dispatch getMovies (I need to reload all Movies afterwards!)
I tried to do it like below, but it just fires the first Action, and I cannot see the other action:
In my log I can see:
[Movie list] Delete movie
[Movie list] Get movies
[Movie list] Get movies successful
I have the folloing actions:
export const getMovies = createAction('[Movie List] Get Movies', props<{search: string, page: number, limit: number}>());
export const getMoviesSuccess = createAction('[Movies List] Get Movies Success', props<{ search: string, page: number, limit: number }>());
export const deleteMovie = createAction('[Movie List] Remove Movie', props<{ movieToDelete: Movie, search: string, page: number, limit: number }>());
export const deleteMovieSuccess = createAction('[Movie List] Remove Movie Success', props<{ movieToDelete: Movie }>());
and the following effect:
deleteMovie$ = createEffect(() => this.actions$.pipe(
ofType(MovieActions.deleteMovie),
mergeMap(({movieToDelete, search, page, limit}) =>
this.moviesService.deleteMovie(movieToDelete)
.pipe(
map(() => MovieActions.deleteMovieSuccess({movieToDelete: movieToDelete})),
map(() => MovieActions.getMovies({search, page, limit})),
catchError(() => EMPTY)
)
)
)
);
How can I trigger BOTH, deleteMoviesSuccess, and getMovies in this order?
I`ve also tried with switchMap and and faltMap, but never are both Actions dispatched correctly.
I just cant seem to understand, how dispatching in an iterative way is possible, but I really need it for my special usecase.
Any help is greatly appreciated.
You should not dispatch two action in as a result of an effect. Rather dispatch some kind of success action and then react on that in other effects. Read here
You could create a chain of effect:
dispatch delete action
on finish of delete dispatch deleteSuccess action
on deleteSuccess action trigger loadMovies effect
on loadMovies success some set action for a reducer to pick up
deleteMovie$ = createEffect(() => this.actions$.pipe(
ofType(MovieActions.deleteMovie),
mergeMap(({movieToDelete, search, page, limit}) => this.moviesService.deleteMovie(movieToDelete).pipe(
map(() => MovieActions.deleteMovieSuccess({movieToDelete: movieToDelete})),
catchError(() => EMPTY)
))
));
loadMovie$ = createEffect(() => this.actions$.pipe(
ofType(MovieActions.deleteMovieSuccess),
mergeMap(() => this.moviesService.loadMovies().pipe(
map(movies => MovieActions.setMovies({ movies })),
catchError(() => EMPTY)
))
));
EDIT
Also instead of passing parameters like limit or search you may hold these in the store. Doing so gives you the advantage to always access those in effects when needed. The NgRx Documentation has a great example on how this selecting in an effect is done. ngrx.io/api/effects/concatLatestFrom
you could use the switchMap operator to return an array of actions.
For example, instead of;
deleteMovie$ = createEffect(() => this.actions$.pipe(
ofType(MovieActions.deleteMovie),
mergeMap(({movieToDelete, search, page, limit}) =>
this.moviesService.deleteMovie(movieToDelete)
.pipe(
map(() => MovieActions.deleteMovieSuccess({movieToDelete: movieToDelete})),
map(() => MovieActions.getMovies({search, page, limit})),
catchError(() => EMPTY)
)
)
)
);
You could try;
deleteMovie$ = createEffect(() => this.actions$.pipe(
ofType(MovieActions.deleteMovie),
mergeMap(({movieToDelete, search, page, limit}) =>
this.moviesService.deleteMovie(movieToDelete)
.pipe(
switchMap(() => [MovieActions.deleteMovieSuccess({movieToDelete: movieToDelete}),
MovieActions.getMovies({search, page, limit})]),
catchError(() => EMPTY)
)
)
)
);

Wordpress Rewrite Rule Anything

I'm trying to create a plugin that adds an "invite" post type that has an "rewrite" param to prepend "convite" before post slug... The code looks like this:
register_post_type("invite_company", [
'label' => __("Empresas", "modaladvisorsplugin"),
'public' => true,
'supports' => ['title'],
'exclude_from_search' => false,
'show_in_rest' => false,
'rewrite' => [
'slug' => "convite",
],
'menu_icon' => "dashicons-building",
]);
At this point, all works fine. Next step is to add an rewrite rule to append anything after the post slug, that will be used in template as a query var... So, for example, this url:
site.com/convite/company/abcdefg
Must recognize abcdefg as a advisor query parameter. For this, I've tried this way:
register_post_type("invite_company", [
'label' => __("Empresas", "modaladvisorsplugin"),
'public' => true,
'supports' => ['title'],
'exclude_from_search' => false,
'show_in_rest' => false,
'rewrite' => [
'slug' => "convite",
],
'menu_icon' => "dashicons-building",
]);
public function rewrite_rules()
{
add_rewrite_rule(
"convite/([a-z0-9-]+)[/]?$",
"index.php?post_type=invite_company&advisor=\$matches[1]",
"top"
);
}
And filtering query_vars as follow:
public function query_vars($vars)
{
$vars[] = "advisor";
return $vars;
}
Sometime (I don't remember what was in regex), when I tried to access /convite/some-post-slug/abcde, the URL was rewritten to /convite/some-post-slug (excluding the appended segment).
By the way, isn't working... I think is a regex problem (maybe convite/([a-z0-9-]+)[/]?$ isn't what I need), but really I don't know what I'm doing wrong, and I'm not an expert in regex...
Can anyone help me?
I'm not sure if I'm fully understanding the requirements, but this might work better. The regex is a bit easier this way, and it should check for both company by itself as well as company with advisor.
add_rewrite_rule('convite/([^/]+)/([^/]+)/?', 'index.php?invite_company=$matches[1]&advisor=$matches[2]', 'top');
add_rewrite_rule('convite/([^/]+)/?$', 'index.php?invite_company=$matches[1]', 'top');
Also, remember to flush rewrite rules before testing (resave permalinks, or run flush_rewrite_rules(); in your code while testing).

Loopback 4 validation returns 422 unexepcted, plus how to require only one of three properties

My application accepts three different types of phone numbers for a model. I'd like to validate the numbers to match a certain pattern only if that number is not empty. I've tried this in declaring the properties, but it causes a 422 because it's trying to apply the validation even when a number isn't present. Is there a way to apply the pattern only when the property is not empty?
#property({
type: 'string',
jsonSchema: {
maxLength: 14,
pattern: "[(][0-9]{3}[)] [0-9]{3}-[0-9]{4}",
},
})
cell_phone: string;
I'd also like to make sure that at least one of them is not empty. It's not clear from the documentation (or I just completely missed it, which has happened) if this is possible outside of checking for at least one of them in the controller. Is there a way to declare this in the model?
I am assuming you are using getModelSchemaRef in your controller which means you could make the property optional by doing something like this
getModelSchemaRef(ModelClass, { optional: ["cell_phone"] })
Alrighty, maybe not the most pretty, but this works.
The phone number properties are defined as so:
type: 'string',
jsonSchema: {
oneOf: [
{pattern: "[(][0-9]{3}[)] [0-9]{3}-[0-9]{4}"},
{maxLength: 0},
],
},
})
home_phone?: string;
#property({
type: 'string',
jsonSchema: {
oneOf: [
{pattern: "[(][0-9]{3}[)] [0-9]{3}-[0-9]{4}"},
{maxLength: 0},
],
},
})
cell_phone: string;
#property({
type: 'string',
oneOf: [
{pattern: "[(][0-9]{3}[)] [0-9]{3}-[0-9]{4}"},
{maxLength: 0},
]
})
other_phone?: string;
Then I just check to make sure the correct phone number is set in the controller, like so:
if (application[primaryPhoneType] === '' || typeof application[primaryPhoneType] === 'undefined') {
throw new HttpErrors.UnprocessableEntity('The primary_phone_type is set to ' + application.primary_phone_type + ' but ' + primaryPhoneType + ' was empty.');
}

I would like to know the regular expression for fulfill the following pattern:

I would like to know the regular expression fulfill the following pattern:
It will accept total 9 digits
After two digit there will be a dash
Not allowed all the zeroes
It should not start with zero
E.g. 12-2322232 --> valid 01-2323232 --> Not valid 00-0000000 --> Not valid
You can use axios, fetch which comes out of the box with React, superagent etc. Here I'll show you how to use axios for server calls:
$npm i -S axios
import axios from 'axios' // import inside the component you will make the request.
//Make the call function.
userDataCallHandler = () => {
axios({
method:'post',
url:'here the api url endpoint',
data:{
name:this.state.name,
password:this.state.password
},
headers:{
'Content-Type':'application/json'
Authorization:'your token if you need it'
}
})
.then(({data}) => {
consolo.log(data)
})
.catch(err => console.log(err));
Visit https://www.npmjs.com/package/axios for further info about it.

How to query mongo db to return all combinations of keys in a search term?

In the mongo db are tags. I'm trying to pull out all the tags that would match starting from the beginning of a search term. Is it possible to achieve the following in a mongo query?
Mongo data:
[
{ tag: '123' },
{ tag: '1234' },
{ tag: '123456' },
{ tag: '987' },
{ tag: '555' }
]
Query search term = '12349339'
Result desired:
[
{ tag: '123'},
{ tag: '1234' }
]
or
[
{ tag: '1234' }
]
I've tried regex expressions to no avail as using (^) would only be useful if the longer search term was in the db and I was searching using a substring.
Update: Here's my regex attempt for anyone trying this approach.
tags.find({tag: {$regex: '^12349339*'}})
Returns nothing. If I wanted all tags that match '123' then this kind of query would work.
tags.find({tag: {$regex: '^123'}})
Returns:
[
{ tag: '123' },
{ tag: '1234' },
{ tag: '123456' }
]
But I wanted the reverse. So, figured I needed an aggregate function or something.
You could do:
{
$where: "'12349339'.indexOf(this.tag) == 0"
}
Obligatory performance note on using $where: The $where provides greater flexibility, but requires that the database processes the JavaScript expression or function for each document in the collection.
https://docs.mongodb.com/manual/reference/operator/query/where/