Insert more records at once in raw_id_fields - django

I have a m2m relation where in my AdminForm I would use raw_id_fields instead of the filter_horizontal option. For explanation I prefer the raw_id_fields instead of the filter_horizontal option, because the records are already categorized. So in the popup-window the user has the ability to search and filter via category.
But there are two points that I can't figure out:
possibility to selecting more than one record in the popup window
showing the real names instead of the pk in the input_field

It's possible. In order to select more than one record, you need to override default dismissRelatedLookupPopup() in django/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js by including your script in the Media class of your ModelAdmin or widget:
var dismissRelatedLookupPopup = (function(prev, $) {
return function(win, chosenId) {
var name = windowname_to_id(win.name);
var elem = document.getElementById(name);
// 1. you could add extra condition checking here, for example
if ($(elem).hasClass('my_raw_id_ext_cls')) { // add this class to the field
// ...logic of inserting picked items from the popup page
}
else { // default logic
prev(win, chosenId);
}
// 2. or you could copy the following part from RelatedObjectLookups.js ...
if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) {
elem.value += ',' + chosenId;
// 2. and add a return. Remember this acts globally.
return;
} else {
document.getElementById(name).value = chosenId;
}
// 3. the following line cause the popup to be closed while one item is picked.
// You could comment it out, but this would also affect the behavior of picking FK items.
win.close();
}
})(dismissRelatedLookupPopup, django.jQuery);
Django does not support this by default. There are some snippets at djangosnippets.org, you may want to take a look at them.

Finally I'm using a modified https://django-salmonella.readthedocs.org/en/latest/. I don't show the input field and show the selected records in a table.

Related

Acumatica-LotSerialNbrAttribute screen on mobile app

I'm using Acumatica customization Acumatica-LotSerialNbrAttribute
This customization adds a new screen for look for InventoryID and LotSerialNbr and visualize its attributes.
I'm trying to add this window to the acumatica mobile app.
Here my code:
add screen IN202501 {
add container "InventoryLotSerialContainers" {
add field "InventoryID"
add field "LotSerialNbr"
add group "Attributes" {
displayName = "Attributes"
collapsable = True
add attributes "AttributesAttributes"
}
add recordAction "Save" {
behavior = Save
}
add recordAction "Cancel" {
behavior = Cancel
}
attachments {
}
}
}
And the screen is visible on the mobile app with the 2 selectors
Then I select Inventory and when I select Lot Serial Nbr, the first selector is in blank, causing that I can't review the attributtes neither save the information.
Here the InventoryID selector in blank.
Hope you can help me to successfully publish this screen on acumatica mobile app.
Thanks.
Attributes are a grid style representation in Acumatica. That means you need a container that will show multiple records. I'm getting rusty on mobile pretty quickly, but I believe your definition is set to display a single value value only.
Try adding a separate container for attributes:
add container "AttributesAttributes" {
add field "Attribute"
add field "Value"
}
This should open into a view of multiple records, showing all of your attributes. By specifying the Attribute and Value fields, you should see both data elements in the container.

Attachments moved away from Item after validation and before submit process in 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.

Ionic 2/3 :Dynamically set RootPage

I have a scenario where I have 2 profiles (user and admin) and I have a selection page once a person logs in. On the selection page, there are 2 radio buttons for (User and Admin profiles), what I am trying to achieve is, the person can choose only 1 profile (this is achieved by the radio button), now assuming I have saved the selected value, I want to set the rootPage to AdminPage or UserPage, but I don't want to immediately navigate, I just want to update/set the path so that when the person goes back (by pressing the back key or previous button) it will take the person to the desired page. Please let me know your thoughts.
Maby this will put you in the right direction:
https://ionicframework.com/docs/api/navigation/NavController/#insert
do not set adminPage or userPage as rootPage but insert the page on the stack
The trick here is that you want to set the root to a new page after the user tries to go back, the easiest way to achieve this is using the NavController navguards to execute a code before leaving the page, this way it'll check wich page the user has selected and then set the root.
Since the select can be easy impemented following the docs i'll leave that aside. Let's just say you have a property userType that is a string and can be 'user' or 'admin', in your select page you'll do the following:
public canLeave: boolean = false; //this'll controll if the user can leave the page or not
public userType: string = 'user'; // just setting a default value to your select
// this is a navguard
ionViewCanLeave() {
if(!this.canLeave){
if(this.userType == 'user'){
this.canLeave = true; // you'll need to set canLeave to true so when setting the rootpage it doesn't enters the if statemente again
this.navCtrl.setRoot('UserPage');
} else {
this.canLeave = true;
this.navCtrl.setRoot('AdminPage');
}
}
return true;
}
Hope this helps.
I got the solution to the error,
ionViewCanLeave() {
if(!this.canLeave){
if(this.userType == 'user'){
this.canLeave = true; // you'll need to set canLeave to true so when setting the rootpage it doesn't enters the if statemente again
this.navCtrl.setRoot('UserPage'); // <-- this should be UserPage instead of 'UserPage'
} else {
this.canLeave = true;
this.navCtrl.setRoot('AdminPage'); // <-- this should be AdminPage instead of 'AdminPage'
}
}
return true;
}

Regex Validation for TreelistEx is not working

In Sitecore Content editor/Page editor, when I add items to TreelistEx I would like the TreelistEx to allow only 12 items. To achieve this solution, I have added a Regex ^.{0,467}$ in the validation field inside the template section in which I want to limit the items.
I have referred this article
This Regex works properly in Content editor. But for the page editor whenever I add an items in treelistEx it works fine for the first time but again if I add/remove items it gives me validation message for both greater and less number of items just after on click of "Ok"and items are also not saved.
Ideally it should give validation message if number of items are greater than 12 and only on Click of "save" button same as it is working in Content editor. How can I solve this Regex validation problem in Page editor? I am using Sitecore 8.1
I also had the same issue a while ago and because of the limited time i had i implemented a not so ideal way but you can implement it if you want.
Let the user add the items and then just grab the first 12 in your code. It will be something like this:
Create a method to get the multicast item (For flexibility).
public static MultilistField GetMultilistField(Item item, string fieldName)
{
if (item != null && !string.IsNullOrWhiteSpace(fieldName))
{
MultilistField field = item.Fields[fieldName];
if (field != null)
{
return field;
}
}
return null;
}
Get the items within the Miltilist field.
MultilistField field = GetMultilistField[DatasourceItem, "fieldName"];
var returnList = field.GetItems().Where(c => c.TemplateName.Equals("someValidationIfYouWant")).ToList().Take(12);

Django admin Many2Many widget customization

I need to customize how the m2m widget for Django Admin gets displayed but I am kind of stumped where to start. I have tried subclassing couple of widgets from django.forms and django.contrib.admin.wigets but nothing seems to be working.
Here's a depiction of what I am looking for http://i.stack.imgur.com/81AY3.png.
Any help appreciated.
That looks like the kind of thing that could be achieved with JavaScript alone. For adding your own JavaScript to the Django admin, see the documentation for ModelAdmin media definitions.
This is what I came up with. It does most of the work. However, the list does not get updated when a new item is added and changing an item does not redirect back to the original page.
/your_app/forms.py
class ProductForm(forms.ModelForm):
class Media:
js = ('js/custom_m2m.js',)
class Meta:
model = Product
/your_media/js/custom_m2m.js
django.jQuery(function() {
var $ = django.jQuery;
// Add a new place holder div to hold the m2m list
$('div.options div').append('<div class="newdiv"></div>');
// Assign some variables
var target = "options"; // <-- Target Field
var newdiv = $('div.newdiv');
var next_page = window.location.pathname;
var add_link = $('div.'+target+' div a#add_id_'+target);
var edit_img = "/static/media_admin/img/admin/icon_changelink.gif";
var add_img = "/static/media_admin/img/admin/icon_addlink.gif";
// Make the placeholder div bit nicer
newdiv.attr("style", "line-height:20px; margin-left:105px;");
// Iterate through select options and append them to 'newdiv'
$('select#id_'+target+' option[selected="selected"]').each(function() {
newdiv.append(''+$(this).text()+' <img src="'+edit_img+'" /><br />');
});
// Add a 'Add new' link after the option list
add_link.html('<strong>Add new</strong> ' + add_link.html());
add_link.appendTo(newdiv);
// Show the 'newdiv' and hide the original dropdown
$('select#id_'+target).after(newdiv);
$('select#id_'+target).css("display", "none");
$('div.'+target+' p[class="help"]').css("display", "none");
});
As you can see, the above script uses some hardcoded paths. Any improvement would be helpful.