Adding Removing Columns to Datagrid in Flex with States - apache-flex

I was developing an app that in the first state you choose a date range using dataFields then you press a button to go to another state and generate a datagrid showing an employee list and another scrollable datagrid with its columns generated dynamically having the worked hours for every employee in every date.
The step sequence to get the error message is:
You choose a date range for example: from 01/01/2013 to 01/31/2013
You press generate button (The app change the currentState = "EmployeeList" and all is OK)
You press the back button (you return to initial state and all is OK)
If you change the date range having more days than before date range then all is OK
If you change the date range having less days than before date range then next error is reached
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.controls.dataGridClasses::DataGridBase/http://www.adobe.com/2006/flex/mx/internal::columnHeaderWordWrap()
at mx.controls.dataGridClasses::DataGridItemRenderer/validateProperties()
at mx.managers::LayoutManager/validateClient()
at mx.controls.dataGridClasses::DataGridHeader/updateDisplayList()
at mx.core::UIComponent/validateDisplayList()
at mx.managers::LayoutManager/validateDisplayList()
at mx.managers::LayoutManager/doPhasedInstantiation()
at mx.managers::LayoutManager/doPhasedInstantiationCallback()
and if you google it then some results take to visit apache bug reporting site
https://issues.apache.org/jira/browse/FLEX-22108
And there is no more...
But I found how to solve it!

To solve it first of all I was googling a lot and i looks like no one got this error and I discover that is a Flex Bug reported to Apache. And I was analyzing the original code from DataGrid.as and DataGridColumn.as to think about a possible solution and I was making some tests and nothing work.
What I did and I hope it will be useful to someone
when you click the back button, inside the backbutton_clickEventLister() and before currentState="";
I just set columns array to new Array();
protected function bttnBack_clickEventHandler(event:Event) : void {
// This code line solved it
dtGrdWorkedHours.columns = new Array();
// Make sure of code it before state change stament
currentState = "";
}

Related

Values from redux store are equal to null

So I am using Redux for state management and I want to take some information from my global state. This is my code:
const vehicleBasicInfo = useSelector((state: AppRootState) => state.vehicleInfo.data);
const { companyName } = useSelector((state: AppRootState) => state.companies);
This is a code that I am using to take both of this values in a tab called Available Vehicle, which is my default tab when I start the application. So when I start the application it takes me directly in this tab and both of my values from the state (vehicleBasicInfo and companyName) are null. When I go to the tab Check more Info where both of these values (vehicleBasicInfo and companyName) are used and presented (In both components I am using the exact same code like in the example here) they are not null and they are correctly shown in this tab. After visiting Check more Info tab and going back to Available Vehicle tab, the values are not null anymore. Can somebody explain me what is happening and how I can fix this in order to have the correct values from my store the first time I open Available Vehicle tab?
Sorry for the long post and I hope someone can help me with this.
EDIT: I needed to do dispatch to get the values.

How to add time widget/picker?

New appmaker user here.
I'm trying to port the work permits approval "app" I made with G Suite form+spreadsheet+GAS; users should enter the day, the start and end time of the permit.
I can see from the Forum Sample that the Date field type is a DateTime field type, so I can use it in my model.
The problem is I cannot find the time picker in the widgets, and the date box has no option to also enter the time.
Am I missing something?
Time Pickers for App Maker
I read your question and thought I'd try to role one of my own and this is what I came up with. I put all of the buttons on a pageFragment and call it with app.showDialog(app.pageFragments.timePicker2);
I only use clientside script.
function updateOutput(){
var h=app.pageFragments.TimePicker2.properties.hour||'00';
var m=app.pageFragments.TimePicker2.properties.minute||'00';
var s=app.pageFragments.TimePicker2.properties.second||'00';
var t=h + ':' + m + ':' + s;
app.pageFragments.TimePicker2.descendants.timeLBL.text=t;
return t;
}
function updateHour(v){
app.pageFragments.TimePicker2.properties.hour=v;
updateOutput();
}
function updateMinute(v){
app.pageFragments.TimePicker2.properties.minute=v;
updateOutput();
}
function updateSecond(v){
app.pageFragments.TimePicker2.properties.second=v;
updateOutput();
}
Here's what my time picker looks like:
Yes. Adding all of the buttons is a nuisance but there are a few features about AppMaker that make it more tolerable.
First you can assign the TimePicker form properties which I use as global properties. I had three hour,minute and second.
Then after you add all of the hour buttons you can grab all of them at one time by clicking each one while holding down control on a windows machine and click on the onClick event and pick custom action and type this in updateHour(widget.text); the code completion won't give you text as an option but type it any way.
I just figured out how to grab the buttons all a one time by pushing shift and selecting with the mouse
Do the same thing with the minute and second buttons using updateMinute(widget.text) and updateSecond(widget.text); This saves you a lot of time typing all of the functions into each widget control panel. Also you don't have to bother giving all of the buttons special names like I did.
But you might like to format them with the following css.
And again you can grab all of the buttons at one time and change the following setting:
That way you can style all of the buttons at one time.
My save button just copies the final string into a label on the main panel.
app.pages.Testing.descendants.timeLBL2.text=app.pageFragments.TimePicker2.descendants.timeLBL.text;
app.closeDialog();
You will probably want to do something more elegant.
Here's a demo: in preview mode. Sorry about the 24 hour clock. I always use this for my own stuff because it's so much easier and I like it. You'll probably want AM & PM. I'll probably go back and do that too.
For an AM/PM Picker I used these functions:
function updateOutputAP(){
var h=app.pageFragments.TimePicker3.properties.hour||'00';
var m=app.pageFragments.TimePicker3.properties.minute||'00';
var s=app.pageFragments.TimePicker3.properties.second||'00';
var ap=app.pageFragments.TimePicker3.properties.ap||' ';
var t=h + ':' + m + ':' + s + ' ' + ap;
app.pageFragments.TimePicker3.descendants.timeLBL.text=t;
return t;
}
function updateHourPM(v){
app.pageFragments.TimePicker3.properties.hour=v;
app.pageFragments.TimePicker3.properties.ap='PM';
updateOutputAP();
}
function updateHourAM(v){
app.pageFragments.TimePicker3.properties.hour=v;
app.pageFragments.TimePicker3.properties.ap='AM';
updateOutputAP();
}
function updateMinuteAP(v){
app.pageFragments.TimePicker3.properties.minute=v;
updateOutputAP();
}
function updateSecondAP(v){
app.pageFragments.TimePicker3.properties.second=v;
updateOutputAP();
}
And this is what my picker looks like:
Now that I know how to pick the components easily with the mouse it was a break to make this change.
Three AppMaker Time Pickers:
At this time App Maker doesn't provide out of the box Time or Date/Time picker widgets, it means that you need to implement one by yourself. There are at least two ways to accomplish this task:
App Maker way
Wait and hope when App Maker will introduce Time or Date/Time picker widget or use existing App Maker widgets to emulate Time Picker. Calendar Sample can be a good starting point:
Hack into DOM/JS
If you have no concerns about cross-browser compatibility and you are OK to get you hands dirty with DOM manipulation by javascript, creating events listeners and other cool stuff, then you can play with HTML widget and native date/time or time input, or even some third party library.
One simple option would be to simply use a textbox and set the validation in the model field.
You can update your Date object on save or just use as is depending on your application. You get the benefit of auto validation errors in the UI to guide your user and it takes only seconds to set up.
Regex:
\b((1[0-2]|0?[1-9]):([0-5][0-9]) ([AaPp][Mm]))

Cannot add new correlated record to new created record

When I create new record in Google AppMaker and then try to add correlated record to this new one I get this warning in console:
com.google.apps.appmaker.client.datasource.AbstractModelDataSource
WARNING: Could not find element with key RecordKey{key=private$7,
model key=...
Both datasources are set to:
Manual save mode
Automatically load data
The problem doesn't appear when I refresh the page or try to add correlated record to other existing record.
Anybody knows what could be a reason for this error?
App Maker doesn't allow to have unsaved changes on both ends of relation, most likely it is a reason, why you recieve error message in the first case. But in theory it should work once you save one of the relation ends (first save one of the records and then link them and save again):
var countryDs = app.datasources.Country;
var capitalDs = app.datasources.Capital;
countryDs.createItem();
countryDs.item.Name = 'United States';
countryDs.saveChanges(function() {
capitalDs.createItem();
capitalDs.item.Name = 'Washington, D.C.';
capitalDs.item.Country = countryDs.item;
capitalDs.saveChanges();
});
OK, I fixed it.
I have two forms. First to create item. Second to edit data. In the first form page need to be set to:
On Detach: Clear Changes To Datasource.
Datasources need to be set to autosave.

ASP.NET DateTime Column in Database Getting Set to Current Date on Page Load

I'm trying to solve an issue where a database column is getting set when navigating to a page in an ASP.NET site. This is a quote management web application, and when opening a quote and navigating to a certain page, the "Expiration Date" is automatically updated to the current date. I have verified that this is occurring prior to triggering the Page_Load function in the ascx.cs file. I have tried to trace what is being run prior to this, but I'm afraid my knowledge of ASP.NET is insufficient, and I don't know exactly where to look. From the pieces I can tell are run prior (for example, the aspx.cs file), I see nothing to indicate any alterations to the record.
When I dig deeper, it seems almost as if the change is taking pace upon leaving the main landing page when editing a quote. If I update the value and travel to any page for the quote except for the main page, it stays the same. And I can travel to the main page, check the record in the database, it stays the same. But it seems like as soon as I navigate from that main page, the Expiration Date will change to the current date. Is there somewhere I can check to see if that's what's happening?
-- EDIT --
Maybe a detail list of actions might help...
View list of quotes in system
Click "Edit" link for quote
View "Quote Details" page, which is first page upon edit access
Look at database query for quote to see exp date is still proper
value
Click "Quote Options" navigation link
See expiration date in "Quote Options" has now changed to current
date
Check database query to see that without performing a known save to
the database the exp date value has updated in the database
Perform update to quote to reset exp date
View any other page in quote edit, return to "Options", see exp
date has not changed again from reset value
Verify proper date with database query
Revisit "Details" page
Again verify correct date with database query
Travel to any other page and then to "Options", or go straight
to "Options", see that exp date has changed to current date
This is the HTML on the link used, which appears to be identical on the other pages...
<a class="tabOff" id="ContentPlaceHolder1_linkButtonAddEditShipping" href='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$ContentPlaceHolder1$linkButtonAddEditShipping", "", true, "", "", false, true))'>Quote Options</a>
I solved the problem. Sort of. I did discover that the save function was being triggered when leaving the "Details" page, even though no save action was being explicitly activated. The problem was resolved by getting the expiration date from the database at the beginning of the function, and if one was set, pushing that value back in at the very end of the function. While this has in effect prevented the value from being "overwritten", I am still unable to determine why the save function was being triggered, and unable to determine what actions within that function are setting the value to be the current date

Can't Edit/Update Certain Items In Database (Table)

I have database that I have multiple orders entered into. Everything seems to be working fine except for a few old entries which will not accept updates/changes to their Fields.
Note: The majority of the Fields are Strings with Possible Values entered via a DropDown Box.
So if I open Order A I can make adjustments just fine and those changes persist even after closing the page and coming back or refreshing.
But if I open Order B, I can make changes via the dropdowns and it looks like they have adjusted, however if I leave the page or refresh all the changes have reverted back.
One piece of info that may be helpful is that each of these orders has at least one Field that contains an entry that is no longer a Possible Value (the original entries were removed/changed per request of the client).
Maybe they are "locked" because of this? Is there a way to look at an error log for a Published app?
I can delete the "corrupt" entries and recreate them (since there are currently only a few), but I would prefer to find a better solution in case this happens again in the future.
Any help would be greatly appreciated.
It's a bug. Such field level value updates should get through.
As workaround you can update prohibited(not possible anymore) values with allowed ones in OnSave Model's Event like:
switch (record.Field) {
case "old_value_1":
record.Field = "new_value_1";
break;
case "old_value_2":
record.Field = "new_value_2";
break;
...
}
Sorry for the inconvenience.
Each deployment has its own log. Have you tried "App Settings > DEPLOYMENTS > (click on the desployment) > VIEW LOGS"?

Resources