New formfield Modal_User : using BS modal with no B/C issue#10772
New formfield Modal_User : using BS modal with no B/C issue#10772cyrez wants to merge 4 commits intojoomla:stagingfrom
Conversation
|
@DGT41 Thanks! Didn't know that... I will see to test repeatable form field, but what is the "javascript part for media and user fields" ? |
|
Thanks! 👍 |
|
wow nice job!! |
@DGT41 cc/ @Fedik I can see to work on a workaround special case for repeatable field, but i don't like the idea: having to write code to be able to work in another form field (subform), and to know that this will be the case for any current and possible upcoming form field type using script. The main issue in subform script is that each time we will change a script or update an external library used in a form field, we will have to update the subform script too... :-( |
|
@JoomliC the problem that Joomla does not have API to work with dynamic content...
Couple note about your pull: |
|
@Fedik Do you have tested this PR with repeatable ?
The same, so this one works Then, i add a new section, and for the second field:
There, both 2 ones are wrong, as it should be: Maybe the issue is when in process, the id is incremented ? (maybe should be incremented before the field is rendered ?) |
|
@JoomliC will be good if you can use the scripts mediafield.js and userfield.js as they already utilise data attributes and there is 0 lines of inline script code!. The problem, and that was the cause that the bootstrap versions of those two fields didn't reach production 3.5, was an incompatibility with the function jSelectUser (or something similar). Patching that then we can have bootstrap modals and the repeatable working as it was originally designed, the regression was here: #9659. So if you take the layouts/fieelds/user.php form #5655 and place it in isis and protostar you get bootstrapped modal. |
|
@JoomliC I not tested with Repeatable , because I see without test that it will not work with Repeatable script 😉 Here a couple piece of code that hardly linked to field ID: all this will fail when someone try to add one more field instance on the page, dynamically. The idea of I agree that would be cool to have something one like |
|
@Fedik Using the field id as BS modal selector was already the way for all modals before this PR, and this is not new ;-) About repeatable, i have check a bit more the code, and think there's a possible issue : incrementation of fields (id and name). @DGT41 & @Fedik i can give a try to integrate in this PR what you have already done (fielduser.js and data-*) but i see this solution as a temporary one (that means i would like to find a solution to use ajax for repeatable subform ;-) ) What's your opinion ? |
|
@Fedik There's an issue with repeatable subform! What i did :
Then check params saved in database : Then, just save again the module (no need to change anything, but same issue if changing values) Check back database : This confirms the fact id is not well incremented... In fact, the php code works well, not the script... :-| |
yes, I know, but it does not means it is right. Using things like
I agree that ID should be unique but it do not required to have any ID. See
I seen this behavior, but it doesn't matter. If you change ordering it can be: Because https://github.com/joomla/joomla-cms/pull/7829/files#diff-bbec1e130dbc3904a847305a6ff41fb8R230 This names do not used and it a "temporary thing".
It would be very cool. But I think you will hit the same problem, Joomla do not have API to work with Dynamic content. 😉 |
Ok, so i will have some changes to do... ;-)
Well... i miss maybe something about repeatable subform... |
Complicated to explain 😄 it just for calculate the field NAME and ID for new field, at start it was just a Unix time, like On start there also was some functionality for keep exact iteration, even if ordering changes it was: If you need some value manipulation before save the subform field, then I would recomend use: $subValues = array_values($data['subformField']);
var_dump($subValues[0]); // first Row
var_dump($subValues[1]); // second Row
...But as I said the iteration does not really matter. Because the Subform script fixes the ID/NAME only for the |
|
@DGT41 and @Fedik Thanks for your feedback, comments and to have opened my mind 👍
So, my intention was to add
Yes, you're definitively right, and so i will review this PR ;-) |
|
for me FieldModal.js is fine 😉 I had some idea before. Maybe I try share it 😃 <div class="field-modal-wrapper">
<input name="blabla" type="text" class="field-modal-input">
<button type="button" class="field-modal-button" data-action="select" data-url="/link-to-select-view">
Select</button>
<button type="button" class="field-modal-button" data-action="clear">
Clear</button>
<button type="button" class="field-modal-button" data-action="edit" data-url="/link-to-edit-view">
Edit</button>
</div>// Bind Click to document (delegation),
// so it allow to catch all dinamicaly added inputs
$(documet).on('click', '.field-modal-button', function(event){
var $btn = $(event.target), // Get clicked button
action = $btn.data('action'), // Get requested action
$wrapper = $btn.closest('.field-modal-wrapper'), // Get wrapper
instance = $wrapper.data('fieldModal'); // Check if we alredy have initialized fieldModal prototype
// Init new instance if there no one
if(!instance){
// Prepare options from data
var options = {}, data = $wrapper.data();
// Check options in the element
for (var p in data) {
if (data.hasOwnProperty(p))
options[p] = data[p];
}
// Set up new instance and attach it to the current field element
instance = new fieldModal($wrapper, options);
$wrapper.data('fieldModal', instance);
}
// Call needed action
instance.applyAction(action, $btn.data());
})
// And in fieldModal code
....
....
$.fieldModal.prototype.applyAction = function(action, options){
if(this[action]){
this[action](options);
} else {
throw new Error('Action "' + action + '" not supported.');
}
}
$.fieldModal.prototype.select = function(options){
// Here call open modal with options.url
}
$.fieldModal.prototype.edit = function(options){
// Here call open modal with options.url for edit
}
$.fieldModal.prototype.clear = function(options){
// Here clear the input value
}
...
...The tricky thing is to handle select in |
|
@Fedik Thank you for ideas! 👍 |
|
@JoomliC any update here or just no time? As this also has conflicts |
|
@zero-24 👍 Thank you to remind me to close this PR, where sadly i have lost time and energy. |
This PR introduces a new form field
Modal_User.Current formfield
useris using mootools modal, and since 3.5, it uses a layout override in Isis template to use Bootstrap modal (with a few B/C issues reported).IMO, not good to manage core improvement in template overrides... as it does not let user manage its own override.
Benefits of this new form field type
type="user"basetype="modal"to define the prefix/path and load the new form fieldModal_Userbasetypeattribute gives facilities for future other changes.If it's ok for this PR concerning the user modal, i can do the same process for
mediaform field! ;-)cc/ @DGT41 @wilsonge : i need your review and comment here, as you know well about the issue with B/C when trying to use Bootstrap modals for user and media form fields ! Thanks! ;-)
Note: i can do this ASAP for Media too, for 3.6.0-beta2, if it's ok with this one about User
Bonus idea: i can migrate category and article modals to use layouts and fields in library for re-usuability (i don't think it should be done for contact, newsfeed... as not directly the base core components).
cc/ @andrepereiradasilva as you will see, i've moved the "no-user" button from the modal content, to the form field (and in addition, a "New" button added to create an new item directly inside a modal. A new feature i will see to add to category, article, and other edit modals ;-) )
Summary of Changes
basetypeto define the path of the form field. eg. "modal" if in path (/libraries/joomla/form/fields/ OR [component]/models/fields/) modal/user.php[basetype]_userEditbutton to allow or not edit of a user (xml attributeedit="true")Newbutton to allow or not to create directly in modal a new user (xml attributenew="true")No Userbutton to allow or not to left field input empty (xml attributeclear="true"or if requiredrequired="true")All questions and feedback are welcome!
Testing Instructions
type="user"in core xml files are updated in this PR.com_banners(Created By + Modified By (readonly))com_categories(Created By + Modified By (readonly))com_contact(User + Created By + Modified By (readonly))com_content(Created By + Modified By (readonly))com_finder(Created By + Modified By (readonly))com_newsfeeds(Created By + Modified By (readonly))com_tags(Created By + Modified By (readonly))com_users(Created By + Modified By (readonly))