How to write directive to allow input field with type= text to allow 'words'? - forms

enter image description here I am using ngxdatatable in reactive forms where user can update all the fields in the table. i have three fields/columns for e.g fields a,b and c and they are dynamic as created below:
-- code for ngxdatatable columns
<div [formgroup]= this.form[rowindex]
<ngx-datatable-column *ngFor="let column of columns; let i = index;" name="{{column.name}}" prop="{{column.prop}}">
<ng-template #buttonsTemplate let-row="row" let-value="value" ngx-datatable-cell-template>
<input type =text isReadonly ="isreadonly">
</ng-template>
</ngx-datatable-column></div>
I am facing challenge in defining my validation for field B/column B,
1. **field b** can be autocalculated as number from field a and field c , **b = a+c**, but
user can't enter number manually in field b , on manual input only few strings are allowed like
'test', 'ok', 'any'. how can I achieve this ?
2. I tried to implement it via custom validation which works fine during manual input but it is failing because field/col B is autocalculated it shows error for number which is a valid scenario , as validation is only to be shown when user tries to input manually.
> this.fb.builder{ field a = validtion.Required,
> validation.patter(_number) field c=validtion.Required,
> validation.patter(_number) field b = customValidator }
>
>
> export function customValidator(c:abstract control) :{key:value}{
> if(c.value=='test' || c.value==''any || c.value == 'ok'} return null
>
> else {allowed:false} }
3. I thought of trying to achieve it with keydown event using directive , but not sure how to write a directive which allows words 'any', 'ok', 'test' and not anything else.**please suggest how can i write the directive for this as I am new to angular.**
4. Please suggest if you think any better approach can be used.

Related

How to get updated HTML radio button in Workflow Inbox?

Since I'm so new for workflow, now I'm stuck at on how to get updated radio button of HTML table in Workflow inbox when click decision button.
STEP 1: ln HTML table, the user can approve or reject WBS by checked radio
STEP 2: When user click confirm, then the workflow will update status for each WBS that shown in the table.
Question:
On STEP 2 - how can I get the HTML text which updated by user action.
For now I've enhanced SAPEVENTS and using 'SAP_WAPI_READ_CONTAINER' to get HTML container.
However, after check the HTML code, the HTML table is not update to user action.
Here's a minimal program which demonstrates how to get the values of the radio buttons. If the user presses Approve on the first line and Reject on the second line, and presses the button Confirm, the method on_sapevent gets group[1]=approve&group[2]=reject.
(works in something like ABAP 7.40 SP8)
REPORT zdemo.
CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS at_selection_screen_output.
METHODS on_sapevent FOR EVENT sapevent OF cl_gui_html_viewer
IMPORTING action frame getdata postdata query_table.
PRIVATE SECTION.
DATA o_html TYPE REF TO cl_gui_html_viewer.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
METHOD at_selection_screen_output.
DATA: l_url TYPE cndp_url,
l_text TYPE string.
IF o_html IS NOT BOUND.
l_text = '<body><form id="form" method="POST" action="SAPEVENT:submit">'
&& REDUCE string( INIT t = `` FOR I = 1 WHILE i <= 2
NEXT t = t && |<div><fieldset id="group{ i }">|
&& |<input type="radio" value="approve" name="group[{ i }]"> Approve |
&& |<input type="radio" value="reject" name="group[{ i }]"> Reject|
&& |</fieldset></div>| )
&& '<p><button type= "submit">Confirm</button></p>'
&& '</form></body>'.
o_html = NEW #( parent = cl_gui_container=>screen0 ).
SET HANDLER on_sapevent FOR o_html.
o_html->set_registered_events( events = value #( ( eventid = o_html->m_id_sapevent ) ) ).
DATA(lt_text) = cl_bcs_convert=>string_to_soli( l_text ).
o_html->load_data(
EXPORTING type = 'text' subtype = 'html' size = strlen( l_text )
IMPORTING assigned_url = l_url
CHANGING data_table = lt_text ).
o_html->show_url( EXPORTING url = l_url ).
ENDIF.
ENDMETHOD.
METHOD on_sapevent.
CONCATENATE LINES OF postdata INTO data(l_post_data) RESPECTING BLANKS.
MESSAGE l_post_data TYPE 'I'.
ENDMETHOD.
ENDCLASS.
PARAMETERS dummy.
DATA go_app TYPE REF TO lcl_app.
LOAD-OF-PROGRAM.
CREATE OBJECT go_app.
AT SELECTION-SCREEN OUTPUT.
go_app->at_selection_screen_output( ).

Dynamic form Issue in Angular

Scenario :
A form is generated dynamically, I used this tutorial to create the form dynamically. When I click "Submit" button, the form value I get in the component is
ts :
doSubmitICR(form) {
console.log(form.value);
}
form.value has the following values
{
CaptainPoint:"0",
Category:"restaurant",
Description:"Test",
DisplayDept:"kitchen",
Group:"restaurant",
GuestPoint:"0",
ItemCode:"1",
ItemName:"Test Item",
PrintingDept:"frontoffice",
SalesRate:"3",
SubGroup:"restaurant",
TAX1:true,
TAX2:true,
TabDisplay:"restaurant",
Unit:"restaurant"
}
TAX1 and TAX2 are dynamic, those form controls were created from a tax table, If the table has TAX3 and TAX4, then instead of TAX1 and TAX2 in the above form, TAX3 and TAX4 form control is generated.
Issue :
If the TAXs are dynamic, how can I pass these values to Web service say WebAPI2 as a model?
Is it possible to filter only the TAX element from the form.value?
Any advice would be appreciated. Thank you.
The solution from alexKhymenko should work well. Alternatively, if the values you want to submit to the API will always have the format of TAX{d}, where d is some combination of digits, you could use the following to get just those values on a request object:
let request = {};
Object.keys(form.value).forEach(key => {
if(/^TAX[\d]+$/.test(key))
request[key] = form.value[key]
});

GravityForms - calculate two fields into a percentage

Hello stack exchange community,
Is it possible to use the internal gravity forms calculate fields function to calculate it into a percentage? I can't find where in the code this calculation happens so i can rewrite how the field outputs. Can anyone point me in the correct direction (as in what hook can i use to rewrite how a form field outputs)?
You'll want to use the "gform_calculation_format_result" JS filter. Copy, paste, and configure the following code in an HTML field on your form.
<script type="text/javascript">
gform.addFilter( 'gform_calculation_format_result', function(formattedResult, result, formulaField, formId, calcObj ) {
// UPDATE: "3" to ID of your Calculation field
if ( formulaField.field_id == 3 ) {
formattedResult = gformFormatNumber( result, ! gformIsNumber( formulaField.rounding ) ? -1 : formulaField.rounding, '.', ',' ) + '%';
}
return formattedResult;
});
Here's an export of a working form if you'd like to import and see this in action (form export).

Adding columns to a Web2py table in a form

In my web2py application, in the controller I read from an external DB the names of students I want to take a register for. I loop through the resulting list adding the list elements to a new list.
for student in pupils_query:
attendance_list.insert(counter, [student[0], student[1], student[2], student[3]])
counter += 1
counter = 0
Then for each student I read their attendance codes for the day so far from another table, and append them to attendance_list:
for attendance_code in attendance_result:
attendance_list[counter].append(attendance_code)
Now, I'm going to want to make a form from all this, using a table which will show each students' attendance code in a text input (so they can be updated if wrong), then have a dropdown for input of the current lesson code.
I'm using a FORM and TABLE helper to create the table in the form:
form=FORM(TABLE(*[TR(*rows) for rows in attendance_list]))
but can't seem to be able to add a new 'row' form item with something like:
select = "SELECT("+ main_reg_list +")"
attendance_list[counter].append(select)
where main_reg_list is dictionary of acceptable attendance codes (or of course, any other form input element).
In summary, I'm stuck adding new TDs to a table made with a TABLE helper from a list of lists. I bet I'm not the first person to overcome this problem.
I am still not clear about what you want. I think you want table of student information and in one column you want dropdown. Something similat to following image
Above form is created from following code.
I hope following code will help you:
# controller/default.py
def index():
# Dummy attendance list, list after appending attendance code
attendance_list = [['stud_id_1', 'first_name_1', 'last_name_1', 'attendance_code_1'],
['stud_id_2', 'first_name_2', 'last_name_2', 'attendance_code_2'],
['stud_id_3', 'first_name_3', 'last_name_3', 'attendance_code_5'],
['stud_id_4', 'first_name_4', 'last_name_4', 'attendance_code_4']]
possible_att_code = ['attendance_code_1', 'attendance_code_2', 'attendance_code_3', 'attendance_code_4', 'attendance_code_5']
# initialise form_rows with Table heading
form_rows = [THEAD(TR(TH('ID'), TH('First Name'), TH('Last Name'), TH('Attendence Code')))]
for attendance in attendance_list:
attendance_code_dropdown = _get_dropdown(attendance[0], attendance[3], possible_att_code)
td_list = [TD(attendance[0]), TD(attendance[1]), TD(attendance[2]),
TD(attendance_code_dropdown)]
table_row = TR(td_list, _id='row_' + attendance[0])
form_rows.append(table_row)
# Form submit button
form_rows.append(TR(INPUT(_type='submit')))
form = FORM(TABLE(*form_rows), _name='student_attendance',
_id='student_attendance')
if form.accepts(request, session):
# Write code to update record
pass
return dict(form=form)
def _get_dropdown(stud_id, att_code, possible_att_code):
option_list = []
for pac in possible_att_code:
if pac == att_code:
option_list.append(OPTION(pac, _value=pac, _selected='selected'))
else:
option_list.append(OPTION(pac, _value=pac))
return SELECT(*option_list, _name=stud_id)
<!-- views/default/index.html -->
{{extend 'layout.html'}}
{{=form}}
Are my assumptions correct? or you want any thing else? Comment if didn't understood code.

Contactform 7 Placeholder Validation

I'm using Contactform 7 for Wordpress. I've edited the text.php and textarea.php to enable the use of placeholders. That works fine.
But, the validation isn't working for some input fields, 'cause the validation thinks the placeholder is the actual text being validated. And yes, ofcourse that validates true 'cause it's not empty.
My input fields with placeholders are as follows:
Your name
Your e-mailadress
Your telephone number
and so on.
In contactform 7's scripts.js I want the validation to check if the input isn't the same as the placeholder. So if the input value is the same as the placeholder value, do the CF7's error validation.
Any idea?
In scripts.js of the contactform 7 plugin folder
Change this:
var submit = form.find('input:submit');
if (! submit.length) return;
with this:
var submit = form.find('input:submit');
if (! submit.length || submit == this.find('[placeholder]').wpcf7Placeholder()) return;