[SOLVED] How to obtain consistency of an element that depends by another?

I have two elements connected each other: CV file and date of CV file.

1.png

Filename in fileupload element disappears after some failed validation.
As explained me cheesegrits in "filename-in-fileupload-plugin-disappears-after-some-failed-validation #post-205203, "this is expected behavior of HTML forms".

Ok, but my problem is that the date of CV file doesn't disappear.

I tried to use a JS event for the element "Curriculum":
2.png

At beginning it worked well, but now (ok, it is strange, I don't know why) it no more works.

How can I solve?
 
Probably, but response time for Standard support is 3 working days. I'm just now getting to your post in my FIFO queue, at 2 days (well, one day and 23 hours).

I'll take a look locally and get back to you within 1 day and 1 hour. Hopefully within a few minute though. ;)

-- hugh
 
I am sorry, my English is not good; I often use google translator.

I apologize twice:
  1. I wrote "No suggestions?" not to Fabrik staff (I know that you answer in 3 days and I know the professionalism and commitment of all of you) but to some other user. Sorry.
  2. My question is not clear. I will write better.
I wrote in onload of "Curriculum" element:
Code:
var nome_curriculum = Fabrik.getBlock('form_74').elements.get('fabrik_nominativi___Curriculum').getValue();
 
alert("nome_curriculum: " + nome_curriculum);
 
if(nome_curriculum === '')
  {
    Fabrik.getBlock('form_74').elements.get('fabrik_nominativi___DataOra_Curriculum').update('');
  }

But, even if in db there is a value in "fabrik_nominativi___Curriculum", alert shows:
"nome_curriculum: " (blank)​
and JS cleans fabrik_nominativi___DataOra_Curriculum.

It seems that
Code:
var nome_curriculum = Fabrik.getBlock('form_74').elements.get('fabrik_nominativi___Curriculum').getValue();
doesn't work well.

If you want, you can
  • go to the site (see MySite)
  • login using
(see MySite)​
  • click on menu "I miei dati" (you will see the alert)
  • click on tab "Lavoro"
You will see:
1.png
because JS cleans "fabrik_nominativi___DataOra_Curriculum".
 
Can you put those login details in your My Sites (link to the left of any of your posts), then edit your post and remove them? This is a public forum, so you don't want to be publishing logins in it. Only Fabrik staff can see the "My Sites" details.

I'll take a look.

-- hugh
 
Hmmm, yeah ... that's going to be problematic, because the fileupload element differs from other elements, in that any existing "value" is not actually in the element. So getValue() is only going to show you if a document has been selected for upload since the page was loaded, such that the HTML input element for it has a value. Any pre-existing file you have uploaded will only be represented in that span above the "Choose File" button, where we put the delete button and the pre-existing uploaded file link.

So the logic won't be as simple as just testing getValue(), you'll also have to test to see if there is an A tag (link) in that span.

Try this:

document.id('fabrik_nominativi___Curriculum_delete_span').getElements('a').length
Code:
var nome_curriculum = Fabrik.getBlock('form_74').elements.get('fabrik_nominativi___Curriculum').getValue();
var nome_curriculum_count = document.id('fabrik_nominativi___Curriculum_delete_span').getElements('a').length
 
alert("nome_curriculum: " + nome_curriculum + " " + nome_curriculum_count);
 
if(nome_curriculum === '' && nom_curriculum_count === 0)
  {
    Fabrik.getBlock('form_74').elements.get('fabrik_nominativi___DataOra_Curriculum').update('');
  }

-- hugh
 
Thank you, hugh.
Ok, I wrote in My Sites and deleted in the post.

Tomorrow morning I will try; I am sure that it works.

Sorry, until now I didn't see the alert by mail.
 
Unfortunately, if "fabrik_nominativi___Curriculum" is empty,
document.id('fabrik_nominativi___Curriculum_delete_span').getElements('a').length;​
causes a JS error:
TypeError: Cannot read property 'getElements' of null

I tried
if (document.id('fabrik_nominativi___Curriculum_delete_span').getElements('a') === null)
{nome_curriculum_count = 0;}
but I got the same error.

How can I work around?
 
Probably test if the span exists, before trying to getElements() on it.

Code:
var  nome_curriculum_count = document.id('fabrik_nominativi___Curriculum_delete_span') ? document.id('fabrik_nominativi___Curriculum_delete_span').getElements('a').length : 0;

-- hugh
 
It works!
Code:
var nome_curriculum_count = document.id('fabrik_nominativi___Curriculum_delete_span') ? document.id('fabrik_nominativi___Curriculum_delete_span').getElements('a').length : 0;
 
if (nome_curriculum_count === 0)
  {Fabrik.getBlock('form_74').elements.get('fabrik_nominativi___DataOra_Curriculum').update('');}

It cleans fabrik_nominativi___DataOra_Curriculum only when fabrik_nominativi___Curriculum is blank.



Last question to get it completely working:
How delete fabrik_nominativi___DataOra_Curriculum when I delete the file?​
xxx.png

I wrote (JS onchange):
Code:
var nome_curriculum = Fabrik.getBlock('form_74').elements.get('fabrik_nominativi___Curriculum').getValue();
 
alert("nome_curriculum=" + nome_curriculum);
 
if (nome_curriculum !== '')
  {
    var data_ora_adesso = new Date();
    Fabrik.getBlock('form_74').elements.get('fabrik_nominativi___DataOra_Curriculum').update(data_ora_adesso);
  }
 
else
  {Fabrik.getBlock('form_74').elements.get('fabrik_nominativi___DataOra_Curriculum').update('');}

It works when I choose a file (fabrik_nominativi___DataOra_Curriculum get the date), but doesn't work when I delete it.

Have I to use an other event?
It seems me that on change of fabrik_nominativi___Curriculum isn't executed on deleting file.
 
Please, last suggestion about

Last question to get it completely working:
How delete fabrik_nominativi___DataOra_Curriculum when I delete the file?​
(see my previous post).
 
That's not so easy as-is, so I just added some code to fire two events, one after the 'soft' delete, one after the 'hard' delete.

https://github.com/Fabrik/fabrik/commit/38b4a72e1ac566b75f0b93e8bbce134efb346828

You'll need to update from github, and then add a form JS file (./components/com_fabrik/js/form_X.js, where X is the numeric form ID, in your case 74). In that, you'd need to do ...

Code:
Fabrik.addEvent('fabrik.fileupload.clearfileref.complete', function (el) {
    if (el.baseElementId == 'fabrik_nominativi___Curriculum') {
        Fabrik.getBlock('form_74').elements.get('fabrik_nominativi___DataOra_Curriculum').update('');
    }
});

That would run on the new 'clearfileref' event, which gets fired when the AJAX call to the server to do the 'soft' delete completes.

-- hugh
 
I made what you wrote, but I have a big issue: some forms are not displayed (white page).
I did not understand what they have in common.

I think that it depends on something updated from Github: I tried to unpublish elements Curriculum and DataOra_Curriculum, but nothing changed.

So, I cannot try your improvement of fileupload element.
But I don't see new clearfileref event; has it to be in the list of Javascript event?
 
I red http://fabrikar.com/forums/index.php?threads/textarea-problem-after-updating.41064/#post-206866, so I update again from Github and the issue regarding textarea elements disappeared.

I tried improvement of fileupload element.
It doesn't work if I answer Yes to deletion of file from directory (2nd question); it works if I answer No.
You wrote it
That would run on the new 'clearfileref' event, which gets fired when the AJAX call to the server to do the 'soft' delete completes.

How can I get that the date is deleted in both cases?


I suggest you an improvement: in parameter you could add
Delete file in directory? YES/NO/ASK​
 
Add a second copy of those lines of code (in the same file), and just change the 'clearfileref' to 'delete'.

We're going to be changing those file deletion options at some point, as they really aren't very intuitive.

-- hugh
 
I am sorry, Hugh, but I didn't realize that there is a JS error:


and http://www.lavoro-over40.com/joomla/components/com_fabrik/js/form_96.js:1:1 shows
Fabrik.addEvent('fabrik.fileupload.clearfileref.complete', function (el) {
if (el.baseElementId == 'fabrik_nominativi___Curriculum') {
Fabrik.getBlock('form_96').elements.get('fabrik_nominativi___DataOra_Curriculum').update('');
}
});

Fabrik.addEvent('fabrik.fileupload.delete.complete', function (el) {
if (el.baseElementId == 'fabrik_nominativi___Curriculum') {
Fabrik.getBlock('form_96').elements.get('fabrik_nominativi___DataOra_Curriculum').update('');
}
});


It seems work, but some other JS in the same page don't.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top