jQuery question: I try to find INPUT fields of a subform, by the id selector, with an regular expression

46 views
Skip to first unread message

Nico van de Kamp

unread,
Oct 19, 2020, 4:13:32 AM10/19/20
to Joomla! General Development
Hello,

I try to find the input field of a subform with the id "jform_flds__fldsx__tlfc", and x=0...n"

My goal is, if a field has already a saved value, it must be readonly. I can't do this for the subform in the model function getForm or is this possible? \
Another thing, on the subform you can add the property "onchange", but not "onload", or am I wrong? Because than I could do it there like an onchange event.

So I thought I do it in the edit.php with jQuery if the document is ready.

Here is my code:
<script type="text/javascript">
    jQuery
('document').ready(function() {
       
//jform_flds__flds0__tlfc      
        jQuery
( window ).on( "load", function() {
           
jQuery('input[id^=jform_flds__flds][id$=__tflc]').each(function() {
               
//jQuery(this).attr('readonly','readonly');
                console
.log('test2: ' + jQuery(this).val());
               
           
});
            console
.log('testx');
       
}); //END jQuery( window ).on( "load", function() {
   
});
</script>

If I change the line:
jQuery('input[id^=jform_flds__flds][id$=__tflc]').each(function() {

Into, without [id$=__tflc] :
jQuery('input[id^=jform_flds__flds]').each(function() {
then all the fields of the subform are returned

I hav tried with and without the line:
jQuery( window ).on( "load", function() {

Has anybody an idea why it is not working? What can be the reason. I have such thing made on another subform and there it is working, I don't see the difference.

And next, to improve this selector should be checking on the digits by regular expressionn like:
jQuery('input[id^=jform_flds__flds\d{1,2}__tflc]').each(function() {

 
I hope that someone can help me to find the issue.
--
Met vriendelijke groet,

Nico van de Kamp
Laakse Laan 37
7207 NA Zutphen
06-27371402

Nico van de Kamp

unread,
Oct 19, 2020, 11:58:09 AM10/19/20
to Joomla! General Development
Sorry all,

I have made a typo. Sorry for that.

I have __tflc in my code and it must be __tlfc how stupid can it be. I have read it so many times and I have used somewere else but I'm not daily busy with jQuery. Spent hours on it.

One thing left does anyone know if it is possible to improve with regular expression like:
jQuery('input[id^=jform_flds__flds\d{1,2}__tlfc]').each(function() {

Or is this not possible?
Reply all
Reply to author
Forward
0 new messages