Angular 6 - Reactive form selection option - Database data versus selection list options - angular6

I have a selection option field that should display the value for the formControlName field from the database and should provide a list of options to choose from.
In this case, it is a project manager who is no longer in the business unit. He will not be listed in the object used for the list of options available in the selection list because he has been transferred to another business unit. His information should still be displayed in the formContralName field though.
His information is available in the formControlName field. I have used a text input field to verify that the information is available and displayed.
The source of the list is a table which is updated through a SQL Server Integration Services (SSIS) task from information recorded in an ERP system. So, any transfers within the company will be synchronized to the system by the SSIS.
This form is used for creating new records, reading and updating existing records.
How can I continue to display historic information (the previously selected project manager) while also providing a list of current options while using a selection option field?
I am looking forward to hearing from.
<label for="selectSpm" class="col-sm-5 col-form-label col-form-label-sm oms-label">SPM<i class="fa fa-question-circle" [popover]="popoverSpm" Preconfigured popover></i></label>
<select class="form-control form-control-sm col-sm-7 oms-textual" style="font-size: 12px;" id="selectSpm" formControlName="senior_proj_man" title="Select the SPM from the list">
<option value="" disabled>Select SPM</option>
<option *ngFor="let spm of spms" [value]="spm.spm">{{ spm.dir + " - " + spm.spm }}</option>
</select>

you have to make (the previously selected project manager) part of an API and you should call this API when you will view this form and in you component when you build the form you should do the following
this.API_SERVICE.METHOD().subscribe(data => {
if(data is available) {
this.buildform(data);
}
});
buildform(data) {
YOUR_FORM = new FormGroup({
senior_proj_man: new FormControl(data.(previously selected project manage));
})
}

Related

How to add timezone drop down in wordpress with contact form 7 plugin?

I am creating a website and it contains query form which includes timezone dropdown .
How can we add time zone drop down using Contact form 7 ??
Attached is output I want.
Thanks in advance!!
You can use the wp_timezone_choice function available within WordPress. This function returns values in <option> form so you can use something of below sort:
<select>
<?php echo wp_timezone_choice( '' ); ?>
</select>
Please note that I have passed empty string so that user can select an option. If you want any timezone to be preselected then you can pass the same timezone instead of empty string.
First of all you will need a timezone database. There are several which you can google for or donwload one from here.
Next import your data into WordPress, if you have a CSV file you can use the plugin Really Simple CSV Importer to import the timezones as a taxonomy for example.
The other option is to import the data as a separate table in your DB, it all depends on how you want to manage the data. If you want to be able to differentiate timezones between different continents/countries/regions then best to store them as a taxonomy and create parent terms for each region you want to differentiate.
Next to display them in your form, use the dynamic dropdown field available with the Smart grid-layout extension plugin.
The dynamic dropdown allows you build a select field using either a list of terms from an existing dropdown (see this video tutorial on how to use it) or using a custom filter and programmatically building the list (see this tutorial) using your database custom table if that's the way you imported your timezone data.
Last but not least, the dynamic dropdown also allows you to transform your select field into a select2 field which is handy for large lists as it allows your users to search for a particular timezone.

Passing variables with Jinja2 within 3 templates

I have this problem:
I have 3 templates:
Search_user
Show_user
Edit_user
Whit the search_user I'm getting the name value with the post method, then I'll search the data in the db, save the data in an array called user and then pass the array to the Show_user template.
In the Show_user template I show the data with {{ user[0] }}, {{ user[1] }}...{{ user[7] }}, under this data I have a button that bring me to the Edit_user template.
But in the Edit_user template I don't know how to pass the previous data, I don't know hot to export data with the post method or any other methods.
A walk around could be <input type="text" name="surname" value="user[0]" required> but I don't want to show the textbox in the Show_user template.
You don't need to pass any data except some kind of user identifier (a number or a user name) to fetch the user back from the database when needed.
It can be done in multiple ways:
add it to the endpoint URL in the form action (/user/edit/<user-id>)
or use your web framework session to store the user identifier
or add the identifier to your templates as a hidden form field (type=hidden)
...
In any case you just need to get that piece of information (from the URL endpoint, from the session, from the form data...), use it to fetch the user from the database, then pass the user to the edit template.
If you're using a web framework just read the docs, this is a trivial use case that we'll be very likely well documented.
If you need more details, please, share a few code fragments.

What's the preferred way to set values for select dropdowns?

I have a select dropdown and I'm wondering about what the best convention is to use when setting the values of the child options.
Here's my form field:
<div class="field">
<label for id="schedule_type">Schedule Type</label><br>
<select name="schedule_type" id="schedule_type">
<option value="recurring">Recurring — Create a series of sessions</option>
<option value="nonrecurring">Not recurring — Create just one session</option>
</select>
</div>
Notice I've used the value "recurring" and "nonrecurring". I've seen examples use integers as well:
<option value="1">Recurring — Create a series of sessions</option>
<option value="2">Not recurring — Create just one session</option>
I am being pedantic? Is there no advantage of one over the other?
Aside from larger [non-trivial] page size (the value 1 vs recurring, there's a minuscule difference in byte that can affect page rendering), there's nothing to problem in the front-end. Though this [might] affect the back-end.
Consider this (back-end agnostic):
I pass the value recurring on form.submit to the server for
processing.
Before saving, the server will first query what is the id of the actual schedule type (that is if it is a foreign key)
Then save.
Against to passing the actual id to the server on save:
I pass the value 1 on form.submit to the server for
processing.
Then save.
The second one will be faster compared to the first one.
But again, depending on the scenario and the design on your back-end, one can be optimal over the other, or it can be negligible at all.

Lightweight web solution that would generate input fields based on the variables listed in the business rules

I need to develop a web-app that would show a list of services provided by our company.One caveat, depending on the value of certain variables(e.g. type of the client, income level, number of children) the cost and duration of the provided services will change.
Notice, that each service is "individual" - it takes different number of variables to form the resulting cost and duration. Now, I am looking for a solution that would allow me to automate the process of input field generation based on the set of variables shown in the business rules.
Right now, I have to MANUALLY create the input fields (most are of radio or dropdown list type) like this
<select id = "myList">
<option value = "myValue1">one</option>
<option value = "myValue2">two</option>
<option value = "myValue3">three</option>
<option value = "myValue4">four</option>
</select>
Showing myValueN is the most painful part.
I have 50 services that I have to show on the list and I would hate to write static html like above.
My business rules are on Guvnor business rule editor by JBoss running on a BRMS(DROOLS) server (version 5.4.0)
Some of the options I can think about:
Parse the generated DRL/BRL using regular expressions.
Use drools-verifier to extract the required information from your DRL/BRL.
Use an enum in Guvnor to store those values (you can use a Java enum). Use that same enum to generate your html page.
Hope it helps,
Did you check the Candidate Release for the new tooling?

Save forms in localstorage

So, I'm working on a site and I need to save some data that it's introduced on a form. The idea is to save that data to query later, like an "archive" of forms. There is no php, no server side, I need to make it all locally. Is there anyway to manage that ?
Thanks
You could try something like this:
JS
//first check to see how many form records exist, if none set to 0 in storage
if (!localStorage.getItem('forms')) {
localStorage.setItem('forms', 0);
}
else {
forms = localStorage.getItem('forms');
}
//increment to the next form entry
forms++;
//save the form data to localStorage
localStorage.setItem('form.' + forms + '.firstName', document.getElementById('firstName'));
//lastly, save the number of forms to localStorage
localStorage.setItem('forms', forms);
HTML
<input type="text" id="firstName" />
This will yield a record in localStorage labeled form.1.firstName. Output would just be another simple check of the number of form records, and looping through the iterations.