Attachments moved away from Item after validation and before submit process in Apex - oracle-apex

I have multiple File Browser Item fields on one page of Application in Oracle Apex.
What happens: When I miss any Item for which validation error fires, I want to hold that file to the browser but I usually loose it if I get that validation error. Is there a solution for the same like other Items fields hold previous value except File Browser Item field. Please see below ss:

Anshul,
APEX 4.2 is very old and no longer supported. A later (or preferably latest) version of APEX will behave differently as Dan explained above.
Can you import your application into apex.oracle.com (which is running APEX 20.1) and you will probably see better results. Based on this you can hopefully use it as justification to upgrade your environment.
Regards,
David

Go to your page-level attributes and a function like the following in the Function and Global Variable Declaration:
function validateItems(request) {
var $file1 = $('#P68_FILE_1');
var $file2 = $('#P68_FILE_2');
var errorsFound = false;
if ($file1.val() === '') {
errorsFound = true;
// Show item in error state
}
if ($file2.val() === '') {
errorsFound = true;
// Show item in error state
}
if (!errorsFound) {
// I think doSubmit was the name of the function back then. If not, try apex.submit
doSubmit(request);
} else {
// Show error message at top of page, I'll use a generic alert for now
alert('You must select a file for each file selector.');
}
}
Then, right-click the Create button and select Create a Dynamic Action. Set the name of the Dynamic Action to Create button clicked.
For the Action, set Type to Execute JavaScript Code. Enter the following JS in code:
validateItems('CREATE');
Finally, ensure that Fire on Initialization is disabled.
Repeat the process for the Save button, but change the request value passed to validateItems to SAVE.

Related

How to create WizardFormPage dynamically in Sitecore?

We are using the WizardForm xml control for implementing some sort of backend sitecore wizard. We want to add the controls to the pages (or even create new custom pages) on the fly, dynamically depending on the selection done in the previous page.
What I've already done: we called a parent control of the page control on the page (in ActivePageChanging event) and tried to add a new object of type "WizardDialogBaseXmlControl" there. But no new pages are displayed in the frontend. I still see the same number of pages in the browser's dev. tools that I added at design time in xml. I tried "SheerResponse.Redraw()", but that didn't help either.
My next attempt was to create some pages in the xml file at design time and just populate them with controls, but that doesn't work after the wizard has already loaded. Something like "ControlName.Controls.Add(new ControlName())" only works if it is called in the overridden method "OnLoad()".
This code doesn't work:
protected override bool ActivePageChanging(string page, ref string newpage)
{
if (newpage.Equals(Consts.PrototypeDetailsPageId))
{
if (IsFormItemSelected(out var formItem))
{
PrototypeDetailsPanel0.Controls.Add(new Literal("some text"));
}
else
{
SheerResponse.Alert("You must select a form item");
return false;
}
}
return base.ActivePageChanging(page, ref newpage);
}
How can I create a working wizard that adds pages and controls at runtime when they depend on changes on previous pages of the same wizard?
Sitecore WizardForm relies on the newpage parameter to process navigation between steps. So you can prepare alternative versions of wizard steps in advance and set one of them as newpage depending on values entered in the previous step. For example, this is how your code can look like:
protected override bool ActivePageChanging(string page, ref string newpage)
{
if (newpage.Equals(Consts.PrototypeDetailsPageId))
{
if (IsFormItemSelected(out var formItem))
{
newpage = "WizardPageWithAdditionalFields";
}
else
{
SheerResponse.Alert("You must select a form item");
return false;
}
}
return base.ActivePageChanging(page, ref newpage);
}
I also found it useful that wizard forms can be easily created with Interactive Dialogs from PowerShell Extensions.
Just as an alternative solution, here is an example of how you can display multiple dialogs to navigate users through a number of steps:
--Prepare step 1
$options = #{
"A"="a"
"B"="b"
}
$props = #{
Parameters = #(
#{Name="selectedOption"; Title="Choose an option"; Options=$options}
)
Title = "Step 1"
}
--Display step 1
$result = Read-Variable #props
if($result -ne "ok") { exit }
--Step 2
if($selectedOption -eq "Expected value") {
--Perform additional logic, for example modify #props to include additional steps
$props = #{
...
}
}
--Display step 2
$result = Read-Variable #props

Unchecking checkbox in oracle apex

Created an report with checkbox using apex_item and when checked more than one check box i will display alert message "not to check more than one checkbox with ok button " after clicking ok it should be unchecked . please find my JavaScript code that displays alert message
if($("input[type=checkbox]:checked").length > 1)
{
var msg = alert('You are not allowed to select more than one employee');
}
It's best to use the APEX JavaScript APIs for this type of thing. You can find them here: https://apex.oracle.com/jsapi
If you're getting started with JavaScript and APEX, you may find these slides useful: https://www.slideshare.net/DanielMcGhan/getting-started-with-javascript-for-apex-developers
Here's a solution that should work for you (just change the name of the item to match yours):
var cbItem = apex.item('P1_CHECKBOX');
if (cbItem.getValue().length > 1) {
alert('You are not allowed to select more than one employee');
cbItem.setValue(); // Passing nothing to clear the value
}

Modifying the Wagtail publish dropdown (per app)

I'd like to reconfigure the default "Publish" menu. The default configuration is this:
I'd like to make Publish the default action, and move it to the top. I'd also like to remove Submit for Moderation, as our site has no current need for that feature.
Ideally, I'd love to be able to override the menu config on a per-app basis - we will likely have other sections of our site in the future where we want a different config.
Is this possible?
This isn't currently possible I'm afraid - the menu items are fixed in wagtailadmin/pages/create.html and edit.html.
This is possible as of Wagtail 2.4 using the register_page_action_menu_item hook, as per Yannic Hamann's answer. Additionally, Wagtail 2.7 (not released at time of writing) provides a construct_page_listing_buttons hook for modifying existing options.
You can add a new item to the action menu by registering a custom menu item with the help of wagtail hooks.
To do so create a file named wagtail_hooks.py within any of your existing Django apps.
from wagtail.core import hooks
from wagtail.admin.action_menu import ActionMenuItem
class GuacamoleMenuItem(ActionMenuItem):
label = "Guacamole"
def get_url(self, request, context):
return "https://www.youtube.com/watch?v=dNJdJIwCF_Y"
#hooks.register('register_page_action_menu_item')
def register_guacamole_menu_item():
return GuacamoleMenuItem(order=10)
Source
If you want to remove an existing menu item:
#hooks.register('construct_page_action_menu')
def remove_submit_to_moderator_option(menu_items, request, context):
menu_items[:] = [item for item in menu_items if item.name != 'action-submit']
The default button SAVE DRAFT is still hardcoded and therefore cannot be configured so easily. See here.
It seems it can't be done on server side without some monkey-patching.
However if you want it for yourself (or have access to computers of those who will publish) you can modify your browser instead.
Install Tampermonkey browser addon
Create new script with a content below
Change http://127.0.0.1:8000/admin/* to your wagtail admin panel url pattern
Save script and check admin panel
Result should look:
// ==UserScript==
// #name Wagtail: replace "Save draft" with "Publish"
// #match *://127.0.0.1:8000/admin/*
// #require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// ==/UserScript==
let $ = window.jQuery;
function modify() {
let draft = $("button.button-longrunning:contains('Save draft')");
let publish = $("button.button-longrunning:contains('Publish')");
if (draft.length && publish.length) {
swap(publish, draft);
}
};
function swap(a, b) {
a = $(a); b = $(b);
var tmp = $('<span>').hide();
a.before(tmp);
b.before(a);
tmp.replaceWith(b);
};
$(document).ready(function() {
setTimeout(function() {
try {
modify();
}
catch (e) {
console.error(e, e.stack);
}
}, 100);
});
Modifying the code above, these selectors works for every admin language:
let draft = $("button.button-longrunning.action-save");
let publish = $("button.button-longrunning[name='action-publish']");

How to dynamically change the list data when click on picker 'done' button in Sencha Touch

I am developing my application in Sencha touch. In that I have a list and Picker and I want to update the list data dynamically when selecting the picker i.e., I want to add data to list dynamically when tap on 'Done' button of Picker. I used some logic for this but this doesn't update the list content.
listeners: {
change: function(picker,value) {
textValue = picker.getValue()['name'];
var me = this,
nameList = this.down('#namesList');
nameList.add({fullname:textValue}) ;
}
}
When I update like this, it throws me the error that 'Uncaught TypeError: Cannot call method 'add' of null' eventhough 'namesList' is already defined. Please show me the way to solve this problem.
I would add a record to the data/store of the list, and then capture the list and refresh.
The issue there is that nameList isnt actually the list component.
Try adding for example an id to the list, and then in the picker change listener:
Ext.getCmp('mylist-id').refresh()
Hope it helps.

How do I utilize the save event in a Sitecore custom Item Editor?

I am creating a custom item editor, and am using the following blog post as a reference for responding to the "save" event in the Content Editor, so that I do not need to create a second, confusing Save button for my users.
http://www.markvanaalst.com/sitecore/creating-a-item-editor/
I am able to save my values to the item, but the values in the normal Content tab are also being saved, overriding my values. I have confirmed this via Firebug. Is there a way to prevent this, or to ensure my save is always after the default save?
I have this in as a support ticket and on SDN as well, but wondering what the SO community can come up with.
Thanks!
Took a shot at an iframe-based solution, which uses an IFrame field to read and save the values being entered in my item editor. It needs to be cleaned up a bit, and feels like an interface hack, but it seems to be working at the moment.
In my item editor:
jQuery(function () {
var parentScForm = window.parent.scForm;
parentScForm.myItemEditor = window;
});
function myGetValue(field) {
var values = [];
jQuery('#myForm input[#name="' + field + '"]:checked').each(function () {
values.push(jQuery(this).val());
});
var value = values.join('|');
return value;
}
In my Iframe field:
function scGetFrameValue() {
var parentScForm = window.parent.scForm;
if (typeof (parentScForm.myItemEditor) != "undefined") {
if (typeof (parentScForm.myItemEditor.myGetValue) != "undefined") {
return parentScForm.myItemEditor.myGetValue("myLists");
}
}
return null;
}
In theory, I could have multiple fields on the item which are "delegated" to the item editor in this way -- working with the content editor save rather than trying to fight against it. I'm a little uneasy about "hitchhiking" onto the scForm to communicate between my pages -- might consult with our resident Javascript hacker on a better method.
Any comments on the solution?
EDIT: Blogged more about this solution