DHTMLX Dynamically populate combo - javascript

I have a working DHTMLX grid that has a number of columns containing Combo Boxes.
A Few of these combo boxes need to be dynamically filled with data after a selection has been made in previous combo boxes.
Eg.
If User Selects a Project of 1234 in the Project Combo Box the Jobs Combo box should only display results from Jobs that belong to Project 1234.
I have been told to use the following functions and methods but cannot work out how to correctly apply them all.
Main APP Javascript code:
JoineryItems = timesheetGrid.getColumnCombo(6);
timesheetGrid.attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){
if(cInd == 4 && stage == 2) {
JoineryItems.clearAll();
JoineryItems.load("data/combo/JoineryItems.php?Project="+nValue);
}
else {}
});
With the following PHP Code in the Server Side Combo Connector
$Project = $_GET[Project];
include_once '../../includes/db_connect.php';
include_once '../../includes/functions.php';
require_once("../../codebase/connector/combo_connector.php");
$data = new ComboConnector($res, "MySQL");
$data->render_sql("SELECT jmpJobID as value, jmpJobID as label from Inf_Jobs where jmpClosed = 0 AND jmpProjectID = $Project",
"jmpJobID",
"jmpJobID(value),jmpJobID(label)"
);
?>
Currently I cannot get the following to function correctly:
JoineryItems.clearAll(); - This Code does not seem to do anything at all even after the code runs the JoineryItems Combo Box still contains values.
JoineryItems.load(...); - Using a browser inspector I can see the results are coming through in XML format but the value is incorrect instead of the value and label being identical the label is coming through correctly and the value is coming through as an odd string of numbers which I cannot determine where they are coming from.
Whenever the onEditCell Event is attached to the grid, updating of my cell values does not occur until after a page refresh. E.G. if a user changes the date of work from the 2nd of March to the 3rd of March the cell displays the 2nd of March until the page is refreshed at which point it then displays the 3rd of march and if multiple changes are made before page refresh than only the last change is made.

Your JavaScript code looks fine with one missing condition:
timesheetGrid.attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){
if(cInd == INDEX_OF_PROJECT_COLUMN){
JoineryItems.clearAll();
JoineryItems.load("data/combo/JoineryItems.php?Project="+nValue);
}
});
Additional if condition will prevent clearing job combo upon edit of any other cell but project column. INDEX_OF_PROJECT_COLUMN will be the index value of the column where you have project combo. Also I have removed extra js variable ProjectID as in the code given there is no need to create that but it is upto you.
Also I do not know PHP but as long as the returned data is something supported by combo then it will work fine. You may check this link for type of data supported. Hope this help.

This is done by the following:
Define Column as a Combo using any of the available methods.
Get the combo column
MyCombo = MyGrid.getColumnCombo(ColumnIndex);
Load the custom
timesheetGrid.attachEvent("onCellChanged",function(rId,cInd,nValue){
if (cInd == 0 ) {
MyCombo.clearAll();
MyCombo.load("data/combo/MyCombo.php?CustomGetVariable="+nValue);
}
Then in php you use your custom variable as part of your select statment and it returns the set of values as combo box options

If you want to load jobs accroding to the project means you should use like below
timesheetGrid.attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){
if(cInd == 4 && stage == 2)
{
var combo2 =timesheetGrid.cells(rId,5).getCellCombo();
JoineryItems.clearAll();
JoineryItems.load("data/combo/JoineryItems.php?Project="+nValue);
}
});

Related

How to access an entered Interactive Grid column value in a Javascript dynamic action on the Change event in order to ensure uniqueness

I am trying to prevent duplicate items from being entered in an Interactive Grid in Oracle Apex 20.2. I do get a unique constraint error when this happens, but this is for a barcode scanning stock control app and the unique constraint error only happens when saving after scanning a room with lots of objects. It is then very difficult to find the duplicate field. You also cannot use sort, since that wants to refresh the page and looses all your scanned items. I cannot presort because I want the last scanned item on top.
I was able to add Javascript on page load that creates an array with all the barcodes. I then check this array when scanning and do not add new Interactive Grid rows when a duplicate barcode is going to be added to the array.
In addition to this I need to add the same for when an Interactive Grid row is manually entered. For this I wanted to add a Javascript dynamic action on the barcode column in the Interactive Grid, in order to once again check the global array for uniqueness. However I have several issues: I cannot figure out how the get the entered barcode value in the change dynamic action Javascript, sometimes it shows the previous changed value (might be this bug although I am in 20.2) and the Change event also seems to fire twice when hitting enter after entering a value (once for the new row (this time my code works unlike when hitting Tab) and once for the next row below). The last one seems bad, since then it will try to check existing values (the next row) and give errors that should not happen; however I do not see a more appropriate event like On Row Submit. Not sure if there is a way to check whether the value changed on the Change event.
The code I currently have I got from here. I am assuming this means Oracle Apex does not have a standard way of getting an Interactive Grid column value in a Javascript dynamic action. Not sure if this has changed in 20.2 or 21. The code I have is:
console.log($(this.triggeringElement));
var grid = apex.region('LINES').widget().interactiveGrid('getViews', 'grid');
var model = grid.model;
var selectedRow = grid.view$.grid('getSelection');
var id = $(selectedRow[0][0]).data('id');
var record = model.getRecord(id);
let bcode = model.getValue(record, 'BARCODE');
console.log(id);
console.log(record);
console.log($(selectedRow[0][0]));
console.log(bcode);
if(barcodes.includes(bcode)) {
apex.message.showErrors([{
type: "error",
location: "page",
message: "The entered barcode is already in the list.",
unsafe: false
}]);
}
When I console.log(record) I can see values that I enter into the barcode column, but I do not know how to walk the object tree in order to retrieve the value out of the record. I do not understand the object it shows me in the console log. It does not seem to correlate with the dot access traversals that others are doing in the above code. I can see the record array at the top, but for that the barcode column shows the previous value; below that it does however show the newly entered value as the third (2) index, but I do not know how to write Javascript to access that.
If I can access the previous and new value from the record object I could check for changes and also compare the new value against the global array. How do I access these values in the record object or is there a better way of achieving my goal? bcode prints the previous value, so I guess I already have that if that is not a bug.

How to add fields dinamically (with a loop?) in ACF for Wordpress?

I've been looking for some help in other questions but none solved my doubts.
I have installed ACF in my Wordpress website that will allow editors to add events and related details. I created some fields inside a field group. Everything's fine apart from one field, event_length (indicates length in days of an event).
This field accepts a number and this number indicates the length of a particular event, in days. When this field is populated with a value (let's call it n), a datetime picker field (so, another field), should be displayed below with label 'Day 1', so that editor can choose the date related to that day. If value is 50, 50 datetime picker fields should be displayed below. I tried to use add_row() function but I have no idea how to use it according to event_length field value.
You need to use the add_row function and load_field filter combined
https://www.advancedcustomfields.com/resources/add_row/
https://www.advancedcustomfields.com/resources/acf-load_field/
I know nothing about your code, but it could look something like this:
function pre_populate_date_rows($date_repeater) {
if (!have_rows($date_repeater) {
$event_length = get_field('event_length', $post_id);
for($i = 0; i < $event_length; i++) {
add_row($field->key, array('time' => get_date(), $post_id);
}
}
}
add_filter('acf/load_field/name=date_repeater', 'pre_populate_date_rows');
Note that I do not know if $field->key is an actual property but you should be able to debug how to get the key from the $field object. Also note that you need to populate your row with default data so I just used the current datetime via get_date

How to extract report based calculation from BRIO report?

How to extract report based calculation from BRIO report ?
For example Multiple Requests
is there public API available to do this task?
Enter code to remove the fields you want to hide from the Results section after the query
finishes processing. For example:
// Eliminate fields from the drill path
ActiveDocument.Sections["Results"].Columns["State"].Remove()
ActiveDocument.Sections["Results"].Columns["Date Ordered"].Remove()
5) Now select the OnPreProcess event and enter code to put the fields back into the Results
section just before processing the query. That way, any dependent computed items will be
properly refreshed. The corresponding code for the current example would be:
// Add the "hidden" fields so computed items can be recalced
ActiveDocument.Sections["Results"].Columns.Add("Date Ordered")
ActiveDocument.Sections["Results"].Columns.Add("State")
Got the API which can add/remove the calculated items but unable to retrive the existing column formula for the computed items, Is there any API even to retreive the column formula
If you are you trying to get the code if(Count ( Account_Id, Account_Id)>1) {'Multiple Requests'} there is an EIS (Dashboard) code ModifyComputed() that allows you to see it as a string: https://docs.oracle.com/cd/E17236_01/epm.1112/ir_user/ModifyComputed_meth.html
If you have no clue what the original code was, I don't think you can extract it, though.

sencha touch: 5 simple questions

I am new to sencha touch and I have some simple questions. I don't need 100% working code as answers, but if someone could point me in the correct direction, this would be great. But keep in mind, sencha touch is new to me. I use sensha touch 1.x.
Let me first explain what my app does. It shows a list with items (fetched from a db via json proxy). You can tap on a item, which shows a form. You can then update or delete the item. On the list screen you can also add a new item. Quite simple :-)
Here are my questions:
1/ Datepickerfield:
In the form there is a datepickerfield. The default format is month/day/year. I live in Europe so the formate should be day/month/year. With slotorder, I can change this. But the field itself still has the wrong format. I tried to fix this with a listener:
change: function() {
this.fieldEl.dom.value = this.getValue().format('d/m/Y');
}
This works when selecting a date. But when tapping an item from the list, the datepickerfield remains the wrong format. I tried using other listeners like afterrender, scope, etc. But nothing works.
2/ Numberfields:
In the model I have a field duration. It is of the type time in the sql-table. So the format is hh:mm:ss. In the form I have 3 numberfields. One for the hour, one for the minutes and one for the seconds.
How can I make the field duration split up into 3 parts and filled in the 3 numberfields when tapping an items from the list?
3/ Contextual selectfield
In the form there is a selectfield with values that depend on the user that is logged in. If user 1 is logged in, the values should be x, y, z. If user 2 is logged in, the values should be x, a, b, etc.
So, when opening the form the selectfield should be pre-filled with data. It should call a function from the server to fetch the correct data. How can this be achieved?
4/ Refresh list like twitter
I want the list to fetch additional items when reaching the end (like twitter). I found something on the Internet: PullRefresh plugin. But I can't make it work.
Any ideas?
5/ Style the list
Is it possible to style each item of a list separately? You can use styleHtmlCls, etc but that styles the whole list.
Thanks a lot in advance.
1 - This is easy set:
picker: {
slotOrder: ["day","month","year"]
}
2 - I dont understand 2 give more clarity
3 - You need to use local storage for this
4 - For paging try this link sencha list paging plugin
5 - You cant directly style each item differently but you can define a style for each item in the list by setting its style config
For those who are interested, my solutions.
1/ This code Ext.apply(Ext.util.Format, {defaultDateFormat: 'd/m/Y'}); which sets the format for all the dates in the application.
2/ I created in my model 3 extra fields. It are 3 "convert" fields for the field "duration" which is in format "hh:mm:ss". This is the code (the same for the fields duration_m and duration_s):
name: 'duration_h',
convert: function(value, record)
{
var duration= record.get('duration'),
splits = duration.split(":"),
duration_h = splits[0];
return duration_h;
}
In my form I use now 3 numberfields linked to those 3 extra fields. When saving you data you must not forget to do
PHP Code:
model.set('duration_h', '');
Otherwise those fields are not set in the model and keep being empty.
3/ and 4/ I did not yet solved.

Populating a drop down based on a text field Javascript/Coldfusion 8

I have a page that has around 30 different entry fields, one of the top fields is a textfield and after this is filled in, I want to populate a dropdown and a textfield. I currently have it calling a javascript function, however my main problem is that I need to query the database to find out what value to populate the fields with.
Here is the type of thing I was trying to do:
function populateState(){
<cfquery name="getState" datasource="#application.dsn#">
SELECT STATE_CODE, CODE_ID
FROM LERG_LATA_V1 LEFT OUTER JOIN Code ON STATE_CODE = CHAR1_TX
WHERE NPX = #NPANXX#
</cfquery>
}
And then after that I would need to read the result and select that element. Any suggestions on how to do this? Most of what I am finding on my google searches are saying you cannot mix cf and js since they execute at different times.
You need to either create a state JavaScript array with your query, and then reference that in your javascript, or use the built-in cfselect tag binding to make this happen. Here's a simple example of how I do this:
http://www.dansshorts.com/post/cfselect-binding-and-selectedvalues
Dan

Categories